![](/img/trans.png)
[英]How to get values from another table in codeigniter using the Active Record?
[英]How to search for multiple values in a single field of mysql table using codeigniter active record?
我必须在codeigniter中使用mysql在一个字段中搜索多个值。 这是我的代码。
在控制器中
public function vpsearch()
{
$data['info'] = $this->psearch_m->emp_search_form();
$this->load->view("employer/result",$data);
}
IN模型
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');
}
}
考虑到 (../雇主/结果)
foreach($info->result() as $row)
{
echo $row->js_id."<br/><br/>" ;
}
但是,我正在获取“ js_edu_details”表中的所有记录,而不是搜索“技能”的字段。
我要去哪里错了? 任何帮助,谢谢,谢谢。
尝试:
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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.