Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use not equal to inside a Yii2 query

Tags:

yii2

In this case you need to use operator format: [operator, operand1, operand2, ...]. So your code should look like this:

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

More about using where method and operator format


You can also try this:

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

for Greater than

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

for less than

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

More check here


Maybe this one help...:)

$query->andFilterWhere([ 'or',
                           ['<=', 'affidavit_cont', 0],
                           ['=', 'affidavit_cont1', 0],
                           ['>', 'affidavit_cont2', 0],
                           ['!=', 'affidavit_cont3', $this->affidavit3],
                           ['in', 'attempt_count', $this->attempted],

                      ]);

$query->andFilterWhere(['like', 'job_invoice.paid_status', '',]);

$query->andFilterWhere(['in', 'status_id', $this->status_id]);

$query->andFilterWhere(['between', 'last_attempt',
    strtotime(Utility::convertDate2Db($this->from_date)),
    strtotime(Utility::convertDate2Db($this->to_date))
    ]);

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();

You can use this

$this->find()->where(['resource_id' => $resource_id]) ->andWhere(['>=', 'start_time', $start_time])->all();