Come cercare più valori in un singolo campo della tabella MySQL utilizzando il record attivo CodeIgniter?

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

Domanda

Devo cercare più valori in un campo usando MySQL in CodeIgniter. Qui segue il mio codice.

In controller

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

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

}

Nel modello

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');
  }
}

In vista ie, (../emplayer/result)

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

Tuttavia, sto ottenendo tutti i record nella tabella "JS_EDU_DETAILS" invece di campi per cercare "abilità".

Dove sto sbagliando? Qualsiasi aiuto ha apprezzato, grazie in anticipo.

È stato utile?

Soluzione

Provare:

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 Dichiarazione dovrebbe essere dopo il like dichiarazione

Altri suggerimenti

Dovresti organizzare il codice correttamente come questo

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');
    }
}

Inoltre, dovresti notare che la condizione non si incontrerà mai. Darà sempre errore undefined variable $jrole

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top