gpt4 book ai didi

php - CodeIgniter 'where' 不工作

转载 作者:行者123 更新时间:2023-11-29 02:25:18 26 4
gpt4 key购买 nike

这是我制作的搜索功能,它获取搜索词并显示正常。 HM_Jobs JobStatus 有 3 个选项: Open , AcceptedComplete .

然而,搜索也从 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();
}

最佳答案

试试这个

 $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'

关于php - CodeIgniter 'where' 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23312807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com