Welcome Guest, Not a member yet? Register   Sign In
where clause order of opperation
#1

[eluser]Unknown[/eluser]
First, id like to thank everyone in the codeigniter community for their contributions.

I have been messing arround with codeigniter for about a week, and am absolutely loving it!

is there any way to set order of opperation in the where clause while stil using the active record object?

this query is generated via active record, but its slightly incorrect:
SELECT DISTINCT `products`.`id`, `products`.`name`, `products`.`content` FROM (`categories`) JOIN `as_products_categories` ON `as_products_categories`.`category_id` = `categories`.`id` JOIN `products` ON `as_products_categories`.`product_id` = `products`.`id` JOIN `as_products_keywords` ON `as_products_keywords`.`product_id` = `products`.`id` JOIN `keywords` ON `as_products_keywords`.`keyword_id` = `keywords`.`id` WHERE categories.category = 'category1' OR `categories`.`category` = 'category2' AND `keywords`.`keyword` LIKE '%testst%'

I would like the where clause to read

(categories.category = 'category1' OR `categories`.`category` = 'category2')
AND
(`keywords`.`keyword` LIKE '%testst%')

as u can see the only diffrence is the parenthesis.

I am aware that i can just use the $this->db->sql($query)
but i was wondering if there is implemented order of operations code within the active record object.

thanks in advance,
Nick
#2

[eluser]Colin Williams[/eluser]
Code:
$this->db->where("(categories.category = ‘category1’ OR `categories`.`category` = ‘category2’) AND (`keywords`.`keyword` LIKE ‘%testst%’)", NULL, FALSE);

The where() function accepts strings, and then you pass NULL, FALSE to keep it from trying to protect identifiers




Theme © iAndrew 2016 - Forum software by © MyBB