长话短说:是否可能,如果是 - 我怎么能建立一个看起来像这个的查询
SELECT * FROM a
WHERE row = 1 AND
(other_row LIKE '%..%' OR another_row LIKE '%..%')
Run Code Online (Sandbox Code Playgroud)
基本上我不能出现/找到解决这个问题的方法.我似乎无法想象如何将括号添加到activerecords查询.这甚至可能吗?
我目前的代码:
$data = $this->where('row', 1)
->like('another_row', '...')
->or_where('row', 1)
->like('other_row', $search)
->get('a')
->result();
Run Code Online (Sandbox Code Playgroud)
结果:
SELECT * FROM (`a`) WHERE `row` = 1 OR `row` = 1 AND `another_row` LIKE '%...%' AND other_row` LIKE '%...%'
Run Code Online (Sandbox Code Playgroud)
你可以试试这个.
$query = $this->db->select('*')
->from('a')
->where('row',1)
->where("(other_row LIKE '%%' OR another_row LIKE '%%' )")
->get();
foreach ($query->result() as $row) {
//do sth.
}
Run Code Online (Sandbox Code Playgroud)
您可以编写自定义查询字符串(来自活动记录类)
Custom string:
You can write your own clauses manually:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
Run Code Online (Sandbox Code Playgroud)