我正在尝试在foreach循环中的WHERE中添加第二个条件。
$customers = Customers::find()->where(['status' => 1])->orderBy('vip DESC, id ASC')->all();
目前,我有过滤where status = 1,但我还需要添加'rank'不等于文本“Can”。
我需要StackOverflow的原因是我试图在网上找到答案,但我有一个文本比较和一个我以前没用过的新查询方法所以我不能很好地研究。
如何在WHERE子句中添加附加条件“AND'level'!='Can'?
如果我不得不猜测它,我会这样写(可能是错的)
$customers = Customers::find()->where(['status' => 1])
->andwhere (['rank' !=> 'Can'])
->orderBy('vip DESC, id ASC')->all();
根据惊人的ActiveQuery documentation,你必须使用andWhere()
方法:
$customers = Customers::find()->where(['status' => 1])
->andwhere (['not', ['rank' => 'Can']])
->orderBy('vip DESC, id ASC')->all();
要么:
->andwhere (['<>', 'rank', 'Can'])
请记住,那qazxsw poi没有qazxsw poi比较运算符!
在Yii,我认为你需要改变,并在哪里和哪里。或试试这个
PHP