gpt4 book ai didi

php - 如何在 yii2 的 AndWhere 中使用嵌套条件

转载 作者:行者123 更新时间:2023-12-05 08:16:32 24 4
gpt4 key购买 nike

在标记为重复问题之前,请阅读它。我在这里有不同的问题。我想使用 yii2 搜索模型生成这种查询。

select * from t1 innerjoin t2 on (t1.id = t2.id) where ((t1.price >= '1000' and t1.price <= '5000') OR 
( t2.price >= '1000' and t2.price <= '5000' ))

在这里加入不是问题。主要问题是 where 子句。我试过了,但没有用。

$query->andFilterWhere([
'and',
['>=', 't1.price', $this>start_price],
['<=', 't1.price', $this->end_price]
])
->orFilterWhere([
'and',
['>=', 't2.price', $this->start_price],
['<=', 't2.price', $this->end_price]
]);

最佳答案

尝试

$query->andFilterWhere([
'or',
[
'and',
['>=', 't1.price', $this>start_price],
['<=', 't1.price', $this->end_price]
],
[
'and',
['>=', 't2.price', $this->start_price],
['<=', 't2.price', $this->end_price]
]
]);

关于php - 如何在 yii2 的 AndWhere 中使用嵌套条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586372/

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