Geoff
Geoff

Reputation: 6629

Yii2 query with comparison value

I would like to find all trucks with certain statuses

So this is the way am doing it

$trucks::TblTrucks::find()
         ->where(["!=" "status", 13])
          ->andWhere(["!=" "status", 14])
          ->andWhere(["!=" "status", 17])
          ->andWhere(["!=" "status", 2])

The above works but looks abiit messed up so i wanted to rewrite it to

$trucks::TblTrucks::find()
         ->where(["!=" "status", [13,14, 17,2])

But the above fails. Where am i going wrong? or how can i rewrite it including all status values in an array.

Upvotes: 0

Views: 64

Answers (1)

HouseInTheForest
HouseInTheForest

Reputation: 96

"!="  

does not work with array in Yii2 and in MySql and you missed the comma after that

Try:

->where(["NOT IN", "status", [13,14,17,2])

More details in the documentation

Upvotes: 2

Related Questions