0

我必须在 codeigniter 中使用 mysql 在字段中搜索多个值。下面是我的代码。

在控制器中

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

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

}

型号

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

鉴于即(../employer/result)

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

但是,我得到了“js_edu_details”表中的所有记录,而不是搜索“技能”的字段。

我哪里错了?感谢您的任何帮助,谢谢。

4

2 回答 2

0

您应该像这样正确安排代码

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

此外,您应该注意条件永远不会满足。它总是会出错undefined variable $jrole

于 2013-11-08T07:08:59.140 回答
0

尝试:

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声明应该在like声明之后

于 2013-11-08T07:00:46.240 回答