我在我的表格中编写了此搜索代码,在show = 1
的帖子中搜索字符串。
但是,当我运行此代码where('show',1)
未受影响以及从数据库返回show = 0
的行时,这是什么问题?
public function json_search($str)
{
$out['Threadt'] = $this->db
->select('id')
->from('posts')
->like('title',$str)
->or_like('story',$str)
->or_like('description',$str)
->or_like('full-story',$str)
->where('date <',time())
->where('show',1)
->get()
->result_array();
}
答案 0 :(得分:0)
你应该尝试这个,这应该有效:
function json_search($str)
{
$where = "( story like '%".$str."%' OR title like '%".$str."%' OR description like '%".$str."%' OR full-story like '%".$str."%' )";
$out['Threadt'] = $this->db
->select('id')
->from('posts')
/*->like('title',$str)
->or_like('story',$str)
->or_like('description',$str)
->or_like('full-story',$str)*/
->where( $where, false, false )
->where('date <',time())
->where('show',1)
->get()
->result_array();
}
请参阅上面评论的部分,当您像这样使用它时,您附加了OR
条款,这会干扰show
条款。