[eluser]davido[/eluser]
I have code like this:
Code:
$this->db->like('fname', $name[0]);
$this->db->or_like('lname', $name[0]);
//AND
$this->db->where("submitted BETWEEN '$begin' and '$end'");
$this->db->or_where("processed BETWEEN '$begin' and '$end'");
Making my query:
Code:
SELECT * FROM users WHERE submitted BETWEEN '2009/1/1' AND '2009/12/31' OR processed BETWEEN '2009/1/1' AND '2009/12/31' AND fname LIKE '%paul%' OR lname LIKE '%paul%'
The problem is I need to have ors have precedence over the ands. I can do this with my dates by having the first AR function start with a paren and the second end with a paren, but doing so on the names would require lots of rewriting of code and I think there should be a better way. So how would I get a query like this in Active Records?
Code:
SELECT * FROM users WHERE (submitted BETWEEN '2009/1/1' AND '2009/12/31' OR processed BETWEEN '2009/1/1' AND '2009/12/31') AND (fname LIKE '%paul%' OR lname LIKE '%paul%')