2016-04-20 11 views
-1

Hallo Leute aus irgendeinem Grund meine Suchfunktion, die nicht mehr gearbeitet funktioniert Ich habe versucht Vielzahl von wie/or_like ohne Erfolg könnte jemand geben Sie eine Hand hier ist mein Controller-Code:Suche arbeitete jetzt ist es nicht funktioniert

 function contractor(){ 
      $keyword = $this->input->post('keyword'); 

      $this->db->like($keyword); 
      $this->db->like('contractor_location',$keyword); 
      $this->db->like('contractor_email',$keyword); 
      $this->db->like('contractor_description',$keyword); 
      $this->db->like('contractor_number',$keyword); 
      $this->db->like('contractor_website',$keyword); 
      $this->db->join('category','contractors.contractorID=category_name.catagory_id','inner'); 
      $this->db->group_by('contractor.contractorID'); 
      $query = $this->db->get('contractors'); 
      return $query->result(); 
    } 

UPDATE: Hier ist die Fehlermeldung, die ich leider erhalte ich es hinzuzufügen vergessen:

A Database Error Occurred 

Error Number: 1064 

You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use 
near 'LIKE '%%' ESCAPE '!' AND `contractor_location` LIKE '%%' ESCAPE 
'!' AND `contr' at line 4 
SELECT * FROM `contractors` INNER JOIN `category` ON 
`contractors`.`contractorID`=`category_name`.`catagory_id` WHERE LIKE 
'%%' ESCAPE '!' AND `contractor_location` LIKE '%%' ESCAPE '!' AND 
`contractor_email` LIKE '%%' ESCAPE '!' AND `contractor_description` 
LIKE '%%' ESCAPE '!' AND `contractor_number` LIKE '%%' ESCAPE '!' AND 
`contractor_website` LIKE '%%' ESCAPE '!' GROUP BY 
`contractor`.`contractorID` 

Filename: modules/search/models/Search_m.php 

Line Number: 38 
+0

Was 'Ist Mittel nicht Werk'? Keine Ergebnisse? Fehler? Haben Sie Nachforschungen angestellt (var_dumps, manuelle Abfragen der Datenbank usw.)? – Pietro

+0

Hallo Entschuldigung, ich habe vergessen, den Fehler hinzuzufügen, siehe oben – RiaanV

Antwort

2

Ihr Code verpassen Name beitreten

$this->db->like($keyword); 

Und Sie haben Fehler in der Tabelle korrigieren

$this->db->join('category','contractors.contractorID=category_name.catagory_id','inner'); 

Corrected Code:

function contractor(){ 
     $keyword = $this->input->post('keyword'); 
     $this->db->like('contractor_location',$keyword); 
     $this->db->like('contractor_email',$keyword); 
     $this->db->like('contractor_description',$keyword); 
     $this->db->like('contractor_number',$keyword); 
     $this->db->like('contractor_website',$keyword); 
     $this->db->join('category','contractors.contractorID=category.catagory_id','inner'); 
     $this->db->group_by('contractor.contractorID'); 
     $query = $this->db->get('contractors'); 
     return $query->result(); 
} 
+0

Vielen Dank für die Tippfehler dort! Die Suche funktioniert, aber ich musste einige Ihrer Antworten ändern, bis ich die gewünschten Ergebnisse erzielt habe. Danke für die Hilfe – RiaanV

1

es ist ein Spaltenname

fehlt

müssen Sie diese Zeile Spalte $this->db->like($keyword);

0

Schlussarbeits-Code ist wie folgt:

 function contractor(){ 
      $keyword = $this->input->post('keyword'); 
      $location = $this->input->post('location'); 
      $industry = $this->input->post('industry'); 

      $this->db->like('contractor_name',$keyword,$industry,$location); 
      $this->db->like('contractor_location',$keyword,$industry,$location); 
      $this->db->like('contractor_email',$keyword,$industry,$location); 
      $this->db->like('contractor_description',$keyword,$industry,$location); 
      $this->db->like('contractor_number',$keyword,$industry,$location); 
      $this->db->like('contractor_website',$keyword,$industry,$location); 
      $this->db->join('catagory','contractors.contractorID=catagory.ID','inner'); 
      $this->db->group_by('contractors.contractorID'); 
      $query = $this->db->get('contractors'); 
      return $query->result(); 
    } 
Verwandte Themen