我尝试通过Active Records在Codeigniter中进行查询:
if (isset($data['where']['and'])) {
$this->db->where($data['where']['and']);
}
if (isset($data['where']['or'])) {
$this->db->or_where_in('idSpec', $data['where']['or']);
}
我想得到:
WHERE name = 1 AND (idSpec = 2 OR idSpec = 3 OR idSpec = 4);
但现在我得到:
WHERE name = 1 OR idSpec = 2 OR idSpec = 3 OR idSpec = 4;
解决方法:
使用以下代码.
if (isset($data['where']['and'])) {
$this->db->where($data['where']['and']);
}
if (isset($data['where']['or'])) {
$this->db->where("(idSpec = 2 OR idSpec = 3 OR idSpec = 4;)", NULL, FALSE);
}