gpt4 book ai didi

mysql - 使用 Zend Db 的多过滤器查询

转载 作者:行者123 更新时间:2023-11-29 00:54:00 25 4
gpt4 key购买 nike

我想使用 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')

有什么想法吗?

最佳答案

$this->where("
(price >= '1000') AND (price <= '1500 ')
OR (price >= '1500') AND (price <= '2000 ')"
);
$this->where("category_id =?", 2);

关于mysql - 使用 Zend Db 的多过滤器查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6978484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com