phpcodeigniteractiverecordwhere-clauselogical-grouping

CodeIgniter active record WHERE clause with mix of AND and OR conditions


I want to ask if I need to do this query in my app

select qty, type
from tItem
where qty=0
    and (type=1 or price=100)

How do I do that using active record in CodeIgniter?

because if I do

$this->db->where('qty','0');
$this->db->where('type','1');
$this->db->or_where('price','100');

the query would be like

select qty, type from tItem where qty=0 and type=1 or price=100

and it's not what I meant to.


Solution

  • You can pass a custom clause, like this:

    $this->db->where('(type = 1 OR price = 100)');