Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用codeigniter活动记录在mysql表的单个字段中搜索多个值?_Php_Mysql_Codeigniter_Active Record Query - Fatal编程技术网

Php 如何使用codeigniter活动记录在mysql表的单个字段中搜索多个值?

Php 如何使用codeigniter活动记录在mysql表的单个字段中搜索多个值?,php,mysql,codeigniter,active-record-query,Php,Mysql,Codeigniter,Active Record Query,我必须在codeigniter中使用mysql在一个字段中搜索多个值。下面是我的代码 在控制器中 public function vpsearch() { $data['info'] = $this->psearch_m->emp_search_form(); $this->load->view("employer/result",$data); } 在型号中 public function emp_search_form() { $ski

我必须在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()作为$row)
{
echo$row->js_id.“

”; }
然而,我得到的是“js_edu_details”表中的所有记录,而不是搜索“skills”的字段

我错在哪里?感谢您的帮助,请提前通知我

试试看:

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

此外,您还应注意,该条件永远不会满足。它将始终给出错误
未定义变量$jrole

尝试您的建议,没有更改。获取表中的所有记录,而不考虑$skills中的值。什么是
$jrole!==空值
?你从哪儿弄来的?编辑了上面的代码,请重试。Thanx Nil'z,发现错误!!我忘了关上视野中的窗户。这就是为什么在$this->db->like('js_skills',$skill);!中无法读取$skill值的原因!!我只是在打印查询后才发现这个。。。非常感谢你的帮助。!!乐于助人,如果能帮助你,请考虑接受答案。
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');
    }
}