Welcome Guest, Not a member yet? Register   Sign In
with parenthesis queries
#1

[eluser]xeroblast[/eluser]
how can i use active record when a query has parenthesis?

SELECT * FROM `table` WHERE `field1`='value1' AND (`field2`='value2' OR `field3`='value2');
#2

[eluser]mdcode[/eluser]
Best way that I have found is to do this (it's in the manual):

Code:
$where = "field1 = 'value1' AND (field2 = 'value2' OR field3 = 'value3')";

$this->db->select('*');
$this->db->from('table');
$this->db->where($where);

$query = $this->db->get();

return $query;

While this has not been tested and it's going from memory from my working system, it should be pretty close to where you want to go...
#3

[eluser]xeroblast[/eluser]
thanx for the reply and i used it that way... i was looking for something like really an active record... but really thanx.. appreciate it...
#4

[eluser]mdcode[/eluser]
No worries mate, pleased it got you where you needed to be. However, the above is the solution found in the Active Record section of the CI User Manual, so it's a fully AR based query.




Theme © iAndrew 2016 - Forum software by © MyBB