我必须使用MySQL在CodeIgniter中的字段中搜索多个值。这里遵循我的代码。

在控制器中

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”表中获得了所有记录,而不是搜索“技能”的字段。

我出错了哪里?任何帮助b都提前感谢。

有帮助吗?

解决方案

尝试:

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 陈述

其他提示

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top