如何在Codeigniter的活动记录SQL查询中使用圆括号符号? 例如如何完成
SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18'
答案 0 :(得分:11)
$where="(`shopid` = '10' OR `shopid` = '11')";
$ this-&gt; db-&gt; 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')
答案 1 :(得分:5)
我认为你可以这样做:
$where = "(`shopid` = '10' OR `shopid` = '11')";
$this->db->where($where) // or statement here
->where('shopid <>', '18') // chaining with AND
->get('shops');
不完全确定语法,我写的是我的头脑。如果这不起作用,我会在回家时看看它。
答案 2 :(得分:1)
您可以执行以下操作:
$this->db->select('field')->from('shops')->where("(`shopid` = '10' OR `shopid` = '11'")->where("`shopid` <> '18'");
$query = $this->db->get();
您可以编写自己的子句 手动:
$ where =“name ='Joe'AND status ='boss' OR status ='active'“;
$这 - &GT; DB-化合物其中($其中);
来源:http://www.codeignitor.com/user_guide/database/active_record.html#where
答案 3 :(得分:1)
$this->db->select()
->from('shops')
->where("'(`shopid` = '10' OR `shopid` = '11')")
->where('shopid !=', 18);
$this->db->get()->result();