D
D
del9937882017-02-13 13:59:24
Yii
del993788, 2017-02-13 13:59:24

How to organize range search in yii2?

Hello. There is yii2, there is a table column "price". Tell me how to organize a search by price range, for example: search from 100 to 200? Maybe there is a module, or is there an article on the implementation of this? I searched but didn't find anything useful. I would appreciate any information on this matter.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-02-13
@qonand

MyModel::find()->where(['between', 'price', 100, 200]);

M
Maxim Timofeev, 2017-02-13
@webinar

Maxim Fedorov gave a working example, I'll add it as an option:

$small = 100;
$big = 200;
MyModel::find()
->andWhere(['>','attribute', $small])
->andWhere(['<','attribute', $big])
->all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question