Wie suche ich in einem einzelnen Feld der MySQL -Tabelle nach mehreren Werten mit dem Active Record von MySQL?

StackOverflow https://stackoverflow.com/questions/19853225

Frage

Ich muss in einem Feld mit MySQL in Codesigniter nach mehreren Werten suchen. Hier folgt meinem Code.

In Controller

public function vpsearch()
{
  $data['info'] = $this->psearch_m->emp_search_form();

  $this->load->view("employer/result",$data);       

}

Im Modell

public function emp_search_form()
{
  $skill = $this->security->xss_clean($this->input->post('ps_skills'));
  $jrole = $this->input->post('ps_jobrole'));


  if ( $jrole !== NULL) 
  {
    return $this->db->get('js_edu_details');
    $this->db->like('js_skills','$skill');
  }
}

Im Hinblick auf dh, (../AMPLETER/RESULT)

foreach($info->result() as $row)
{
  echo $row->js_id."<br/><br/>" ;
}

Ich erhalte jedoch alle Datensätze in der Tabelle 'JS_EDU_Details' anstelle von Feldern, die nach "Fähigkeiten" gesucht haben.

Wo gehe ich falsch? Jede Hilfe wud b schätzte, danke im Voraus.

War es hilfreich?

Lösung

Versuchen:

public function emp_search_form()
{
    $skill = $this->security->xss_clean($this->input->post('ps_skills'));
    //$skill = $this->input->post('ps_skills', true);  other short way of getting the above result with `xss clean`
    if ( $jrole !== NULL) 
    {
        $this->db->like('js_skills',$skill); #remove the single quote around the `$skill`
        $res = $this->db->get('js_edu_details');
        echo $this->db->last_query(); #try to print the query generated
        return $res;
    }
}

Return Aussage sollte nach der sein like Aussage

Andere Tipps

Sie sollten den Code so ordnungsgemäß anordnen

public function emp_search_form()
{
    $ps_skills  =   $this->input->post('ps_skills')
    $skill      = $this->security->xss_clean($ps_skills);

    if ( $jrole !== NULL) 
    {
        $this->db->like('js_skills','$skill');
        return $this->db->get('js_edu_details');
    }
}

Sie sollten auch beachten, dass sich die Bedingung niemals erfüllen wird. Es wird immer Fehler geben undefined variable $jrole

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top