How to use not equal to inside a Yii2 query

2019-03-11 14:42发布

I want to use a yii2 query in which i want to check a not equal to condition. I tried like this but it didn't give the desired results. how do i do it?

$details        =   MovieShows::find()->where(['movie_id'=>$id])
                    ->andWhere(['location_id'=>$loc_id])
                    ->andWhere(['cancel_date'=>!$date])->all();

标签: yii2
9条回答
老娘就宠你
2楼-- · 2019-03-11 15:35

You can use this

$this->find()->where(['resource_id' => $resource_id]) ->andWhere(['>=', 'start_time', $start_time])->all();
查看更多
狗以群分
3楼-- · 2019-03-11 15:37

The better and safe way to apply a condition.

Booking::find()->where('tour_id = :tour_id and id != :id', ['tour_id'=> $chk->tour_id, 'id' => $id])->all();
查看更多
淡お忘
4楼-- · 2019-03-11 15:40

In case anyone reading this needs to use a REGEXP or similar, this works in Yii2 (2.0.15.1):

->andWhere(['NOT REGEXP', 'column','[A-Za-z]'])

查看更多
登录 后发表回答