我有几个与 OR 相关的条件的请求。在模块中:
$array = array('hostel.postal_code' => $filter_state, 'region.name' => $filter_state, 'hostel.town' => $filter_state, 'state.name' => $filter_state);
$this->db->or_like($array);
我看到sql:
WHERE `bp_hostel`.`status` = 'A'
AND `bp_hostel`.`postal_code` LIKE '%Vic%'
OR `bp_region`.`name` LIKE '%Vic%'
OR `bp_hostel`.`town` LIKE '%Vic%'
OR `bp_state`.`name` LIKE '%Vic%'
ORDER BY `view_count` desc
我对请求有疑问,我想设置“(...)”以确保我的 sql 是正确的,例如:
WHERE `bp_hostel`.`status` = 'A'
AND ( `bp_hostel`.`postal_code` LIKE '%Vic%'
OR `bp_region`.`name` LIKE '%Vic%'
OR `bp_hostel`.`town` LIKE '%Vic%'
OR `bp_state`.`name` LIKE '%Vic%' )
ORDER BY `view_count` desc
我在文档中读到:
You can wrote your requests by hands:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
但我发现这个变体不方便,因为我不喜欢将所有条件都写成 1 个字符串。在此方法方法中,还有一些 SQL 条件...
这个怎么做?