Comment rechercher plusieurs valeurs dans un seul champ de la table MySQL à l'aide de l'enregistrement actif Codeigniter?

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

Question

Je dois rechercher plusieurs valeurs dans un champ en utilisant MySQL dans CodeIgniter. Ici suit mon code.

Dans le contrôleur

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

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

}

Dans le modèle

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

En vue c'est-à-dire (../Employer/result)

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

Cependant, je reçois tous les enregistrements dans le tableau «JS_EDU_DETAILS» au lieu de champs ayant recherché des «compétences».

Où je vais me tromper? Toute aide Wud B a apprécié, merci à l'avance.

Était-ce utile?

La solution

Essayer:

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 La déclaration doit être après le like déclaration

Autres conseils

Vous devez organiser le code correctement comme ça

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

Vous devez également noter que la condition ne se réunira jamais. Il donnera toujours une erreur undefined variable $jrole

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top