A
A
alex_belouss2017-01-30 15:47:46
Yii
alex_belouss, 2017-01-30 15:47:46

How to set a condition from and to in Yii2?

There is a price field,
there are two fields in the search, price from and to, how do I set a condition to select records in a given interval?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-01-30
@webinar

$prosucts = Product::find()->andWhere(['>','price',15])->andWhere(['<','price',100])->all();

But when it comes to search, it's probably more convenient to use ActiveDataProvider and SearchModel, then it's almost the same:
$query->andFilterWhere(['>','price',$this->min])->andFilterWhere(['<','price',$this->max]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question