Answer the question
In order to leave comments, you need to log in
How to make a condition on several parameters of one field in Yii2?
There is such a request, how can it be translated into yii2?
SELECT * FROM `work_news` WHERE `text` != ' ' AND `status` != 'wait' AND `status` != 'hide' AND `status` != 'ban';
The status field - enum type - contains show, hide, wait, ban.
I collected this one, but status does not work.
$queryNews = (new Query())->select(['*'])
->from('work_news')
->where(['hot_news' => '0'])
->andWhere(['not' , ['text' => null, 'status' => ['wait', 'hide', 'ban']]])
->orderBy(['created_date' => SORT_DESC])
->limit(1)
- >createCommand()->
Answer the question
In order to leave comments, you need to log in
firstly, why would you exclude 3 statuses, if you can just look for records with the show status? secondly, 'text' => null in the query above, you check the field for not emptiness, but emptiness and NULL are different values
$queryNews = (new Query())->select(['*'])
->from('work_news')
->where(['hot_news' => '0', 'status' => 'show'])
->andWhere(['<>', 'text', '""']])
->orderBy(['created_date' => SORT_DESC])
->limit(1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question