Reputation: 7109
I would like to create a price and category filter using PHP and Zend Db. Works perfectly when filter independently by price or category
How to generate following query using Zend DB
SELECT * FROM `products` WHERE
(
(price >= '1000') AND (price <= '1500 ')
OR
(price >= '1500') AND (price <= '2000 ')
)
AND (category_id = '2')
Tried as follows,
$this->where('price > ?', '1000')->where('price < ?', '1500');
$this->orwhere('price > ?', '1500')->where('price < ?', '2000');
$this->where('category > ?', '2');
but it generates,
SELECT * FROM `products` WHERE
(price >= '1000') AND (price <= '1500 ')
OR
(price >= '1500') AND (price <= '2000 ')
AND (category_id = '2')
Any idea?
Upvotes: 1
Views: 334
Reputation: 4330
$this->where("
(price >= '1000') AND (price <= '1500 ')
OR (price >= '1500') AND (price <= '2000 ')"
);
$this->where("category_id =?", 2);
Upvotes: 1