我尝试通过 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);
}
关于php - 如何在 CI 中使用 OR 和 AND 运算符进行查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29143828/