且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

代码WHERE和OR在一起

更新时间:2022-12-12 20:24:50

刚刚找到的解决方案,如果它可以帮助一些。

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


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.

Just found solution, if it can help some one.

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