我可能需要一些帮助来嵌套一个类似的查询。 我的目标是完成类似的事情:
Select * from 'Library_Book'
WHERE(
('BookName' LIKE '%FILTER1%' OR 'BookDescription' LIKE '%FILTER1%')
AND
('BookName' LIKE '%FILTER2%' OR 'BookDescription' LIKE '%FILTER2%')
)
到目前为止,我的方法是:
$this->db->select('Library_Book.*');
foreach($filter as $fltr){
$this->db->like('Library_Book.BookName', $fltr);
$this->db->or_like('Library_Book.BookDescription', $fltr);
}
$records = $this->find_all();
这导致:
Select * from 'Library_Book'
WHERE(
'BookName' LIKE '%FILTER1%' OR 'BookDescription' LIKE '%FILTER1%'
AND
'BookName' LIKE '%FILTER2%' OR 'BookDescription' LIKE '%FILTER2%'
)
如何获得or_like语句的括号?
由于
tutschdamoon
#CI-BONFIRE ver 0.7
模块/ mymodul /模型/ mymodel_model.php
答案 0 :(得分:0)
来自Bonfire的lonnieezell所说的答案。
我测试了它并且有效。
$wheres = array();
foreach ($filter as $fltr)
{
$wheres[] = "('BookName' LIKE '%{$fltr}%'' OR 'BookDescription' LIKE '%{$fltr}%')";
}
$this->db->where( implode(' AND ', $wheres), null, false);
$records = $this->find_all();