CodeIgniter Forums
active records: logical operators priority - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: active records: logical operators priority (/showthread.php?tid=45751)



active records: logical operators priority - El Forum - 10-04-2011

[eluser]lord_nerevar[/eluser]
Hi.
I am using active record class and i'm really happy with them, but i have a trouble.

if i write this:
$this->db->where('name', 'john');
$this->db->where('title','sir');
$this->db->or_where('status', 'single');

the sql query will be:
...WHERE (name = 'john' AND title = 'sir') OR (status = 'single')

if i want this output:
...WHERE (name = 'john') AND (title = 'sir' OR status = 'single)

where clauses depends from user input, so i can't preview how many clauses will need the query, i take the where clauses from another table made of 2 fields.

filter | value

filter can contain more times the same filter with different values (in this case i want to add OR statement) or different filter (here i want AND)

example:

filter | value
age 11-20
age 21-30
sex m

i want
WHERE (age = '11-20' OR age = '21-30') AND sex = 'm'
how can i do?

(sorry for my bad english)