Wasim A. Wasim A. - 11 days ago 6
PHP Question

Codeigniter WHERE AND OR together

I am trying to combine Where And OR in Codeigniter via code.

$this->db->where("id",1);
$this->db->where("status","live")->or_where("status","dead");


Appeared result is as query

where id=1 and status='live' OR status='dead'


Whereas i need result for this query.

where id=1 and (status='live' OR status='dead');


NOTE: Please don't give solution of string passed as parameter from where function. That's not fit into my code. I Just simplified my problem above.

Answer

Just found solution, if it can help some one.

$this->db->where("id",1)->where("(status='live' OR status='dead')");