3

I want to make multiple where query, with both < and = operators.

With multiple = operators it goes like:

Model::find()->where([
    'param1' => 0,
    'param2' => 0,
])->all();

With one < operator

Model::find()->where([
    '<', 'param1', 0
])->all();

How can I apply both these conditions in one where array?

2 Answers 2

8

You can use a combination of where andWhere

   Model::find()->where([param1' => 0 ])
          ->andWhere(['>','param2' , 0])->all();

adding the operator to you clause see operator format

http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html

Sign up to request clarification or add additional context in comments.

Comments

4
Model::find()->where([
    'and',
    [
        'param1' => 0,
        'param2' => 0,
    ],
    ['<', 'param1', 0]
])->all();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.