0

在嵌套类似查询时,我可能需要一点帮助。我的目标是完成类似以下的事情:

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 语句周围的括号?

谢谢

图奇达蒙

#

CI-BONFIRE 版本 0.7

模块/mymodul/models/mymodel_model.php

4

1 回答 1

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();
于 2013-11-21T13:31:24.117 回答