how to used IN & Between Clause in YII ACtive Record?

后端 未结 7 1669
轻奢々
轻奢々 2021-02-14 10:15

I want write a Following Query in Active record .

SELECT *
FROM `User`
WHERE `UserId`
IN ( 6, 7, 8, 9 ) ;

Thanks

7条回答
  •  有刺的猬
    2021-02-14 10:44

    There is an function called findAllBySql in yii to run sql query and get the outputs.

    $sql="SELECT * FROM `User` WHERE `UserId` IN ( 6, 7, 8, 9 )";//Your Sql query
    $value=User::model()->findAllBySql($sql);// "User" is the model belongs to the table 'User'
    

    The "$value" will return the result in a array. To get the values you can use the following method.

    foreach($value as $val){
       echo $val->UserId;
    }
    

    (or)

    var index=0;
    echo $val[$index]->UserId;
    

提交回复
热议问题