这是我制作的搜索功能,它获取搜索字词并显示正常。 HM_Jobs
为 JobStatus提供了3个选项: Open
,Accepted
或Complete
。
然而,当我运行时,搜索也会从Accepted
和Complete
行中提取结果,为什么WHERE语句不会阻止这种情况发生?
function search_jobs($search) //This function checks a search term against the job title and description.
{
$this->db->select('*');
$this->db->from('HM_Jobs');
$this->db->like('JobTitle',$search);
$this->db->or_like('JobDescription',$search);
$this->db->where('JobStatus','Open');
$query = $this->db->get();
return $query->result();
}
答案 0 :(得分:1)
试试这个
$this->db->select('*');
$this->db->from('HM_Jobs');
$this->db->where("(JobTitle LIKE '$search' OR JobDescription LIKE '$search')" );
$this->db->where('JobStatus','Open');
$query = $this->db->get();
您可以使用echo $this->db->last_query()
您的查询就像
一样where JobTitle like 'search' or JobDescription like 'search' and JobStatus='Open'
但您需要的查询需要类似
的内容 where (JobTitle like 'search' or JobDescription like 'search') and JobStatus='Open'
答案 1 :(得分:1)
尝试使用以下查询
function search_jobs($search)
{
$query = $this->db->select('*')
->from('HM_Jobs')
->where('JobStatus','Open')
->where("(`JobTitle` LIKE '%$search%' OR
`JobDescription` LIKE '%$search%')",null,false)
->get();
return $query->result();
}