使用 Zend Db 进行多重过滤查询

发布于 2024-11-28 12:54:44 字数 758 浏览 0 评论 0原文

我想使用 PHP 和 Zend Db 创建价格和类别过滤器。按价格或类别独立过滤时工作完美

如何使用 Zend DB 生成以下查询

SELECT * FROM `products`  WHERE 
    (
        (price >= '1000') AND (price <= '1500 ')
        OR 
        (price >= '1500') AND (price <= '2000 ') 
    ) 
    AND (category_id = '2') 

尝试如下,

$this->where('price > ?', '1000')->where('price < ?', '1500');
$this->orwhere('price > ?', '1500')->where('price < ?', '2000');

$this->where('category > ?', '2');

但它生成,

SELECT * FROM `products`  WHERE 
    (price >= '1000') AND (price <= '1500 ')
OR 
    (price >= '1500') AND (price <= '2000 ') 
AND (category_id = '2')

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沐歌 2024-12-05 12:54:44
$this->where("
              (price >= '1000') AND (price <= '1500 ') 
              OR (price >= '1500') AND (price <= '2000 ')"
);   
$this->where("category_id =?", 2);
$this->where("
              (price >= '1000') AND (price <= '1500 ') 
              OR (price >= '1500') AND (price <= '2000 ')"
);   
$this->where("category_id =?", 2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文