【问题标题】:Codeigniter - brackets with activerecord?Codeigniter - 带活动记录的括号?
【发布时间】:2011-05-30 11:38:38
【问题描述】:
如何在 Codeigniter 的活动记录 SQL 查询中使用圆括号符号?
例如如何完成
SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18'
【问题讨论】:
标签:
codeigniter
activerecord
【解决方案1】:
$where="(`shopid` = '10' OR `shopid` = '11')";
$this->db->where($where, NULL, FALSE);
对于AND条件使用
$this->db->where('shopid <>', '18')
即
$where="(`shopid` = '10' OR `shopid` = '11')";
$this->db->where($where, NULL, FALSE);
$this->db->where('shopid <>', '18')
【解决方案2】:
我认为你可以这样做:
$where = "(`shopid` = '10' OR `shopid` = '11')";
$this->db->where($where) // or statement here
->where('shopid <>', '18') // chaining with AND
->get('shops');
不完全确定语法,我是在脑海中写下这个。如果这不起作用,我会回家看看。
【解决方案4】:
$this->db->select()
->from('shops')
->where("'(`shopid` = '10' OR `shopid` = '11')")
->where('shopid !=', 18);
$this->db->get()->result();