SELECT * FROM cdr WHERE (Circle LIKE '%D%' OR CLI LIKE '%D%' OR Operator LIKE '%D%') AND Dept = 'Sale'
我只想像 $this->db->like('Circle','%D%') 一样,部门带有 'and'。
您应该阅读 codeigniter 文档,这是一个简单的文档:
$this->db->where("(Circle LIKE '%D%' OR CLI LIKE '%D%' OR Operator LIKE '%D%')")
->where("dept", "Sale");
$query = $this->db->get("cdr");
http://www.codeigniter.com/user_guide/database/active_record.html
只需将关联数组提供给
or_like()
并用 group_start()
和 group_end()
将这些条件封装在括号中。
return $this->db
->group_start()
->or_like(['Circle' => 'D', 'CLI' => 'D', 'Operator' => 'D'])
->group_end()
->get_where('cdr', ['Dept' => 'Sale'])
->result();
如果需要,
or_like()
可以更干燥:->or_like(array_fill_keys(['Circle', 'CLI', 'Operator'], 'D'))
渲染的 SQL:
SELECT *
FROM `cdr`
WHERE (
`Circle` LIKE '%D%' ESCAPE '!'
OR `CLI` LIKE '%D%' ESCAPE '!'
OR `Operator` LIKE '%D%' ESCAPE '!'
)
AND `Dept` = 'Sale'