Welcome Guest, Not a member yet? Register   Sign In
active records: logical operators priority
#1

[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)




Theme © iAndrew 2016 - Forum software by © MyBB