开发者

Codeigniter - brackets with activerecord?

开发者 https://www.devze.com 2023-03-09 10:30 出处:网络
How to have round brackets symbol in Codeigniter\'s active record SQL queries? e.g. how to a开发者_JAVA百科ccomplish

How to have round brackets symbol in Codeigniter's active record SQL queries? e.g. how to a开发者_JAVA百科ccomplish

SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18'


$where="(`shopid` = '10' OR `shopid` = '11')";

$this->db->where($where, NULL, FALSE);

and for the AND condition use

$this->db->where('shopid <>', '18')

ie

$where="(`shopid` = '10' OR `shopid` = '11')";
$this->db->where($where, NULL, FALSE);
$this->db->where('shopid <>', '18')


I think you could do something like:

$where = "(`shopid` = '10' OR `shopid` = '11')";

$this->db->where($where)  // or statement here
         ->where('shopid <>', '18') // chaining with AND
         ->get('shops');

Not entirely sure about the syntax, I'm writing this off the top of my head. I'll take a look at it when I get home if this doesn't work.


You can just do something like:

$this->db->select('field')->from('shops')->where("(`shopid` = '10' OR `shopid` = '11'")->where("`shopid` <> '18'");
$query = $this->db->get();

You can write your own clauses manually:

$where = "name='Joe' AND status='boss' OR status='active'";

$this->db->where($where);

Source: http://www.codeignitor.com/user_guide/database/active_record.html#where


$this->db->select()
         ->from('shops')
         ->where("'(`shopid` = '10' OR `shopid` = '11')")
         ->where('shopid !=', 18);

$this->db->get()->result();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号