I want write a Following Query in Active record .
SELECT *
FROM `User`
WHERE `UserId`
IN ( 6, 7, 8, 9 ) ;
Thanks
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;