Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter - brackets with activerecord?

How to have round brackets symbol in Codeigniter's active record SQL queries? e.g. how to accomplish

SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18'
like image 630
Gretchen Avatar asked May 30 '11 11:05

Gretchen


2 Answers

$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')
like image 196
Deepti Kanika Avatar answered Nov 27 '22 18:11

Deepti Kanika


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.

like image 39
Joris Ooms Avatar answered Nov 27 '22 18:11

Joris Ooms