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();
精彩评论