Issue
I need to use where clause on yii, below of my code, I need to add where activated == 0 && send_email == 0.
$model = User::model()->findAll();
Thanks
Solution
There are multiple ways to do this:
$model = User::model()->findAll('activated=0 AND send_email=0');
Or,
$model = User::model()->findAll('activated=:activated And send_email=:sendEmail',
array(':activated'=>0,':sendEmail'=> 0));
Or,
$criteria = new CDbCriteria;
$criteria->condition='activated=:activated AND send_email=:sendEmail';
$criteria->params=array(':activated'=>0,':sendEmail'=>0);
$model=User::model()->findAll($criteria);
Or,
$model = User::model()->findAllByAttributes(array('activated'=>0, 'send_email'=>0));
Or,
$model = User::model()->findAllBySql('SELECT * FROM user WHERE activated=:activated AND send_email=:sendEmail', array(':activated'=>0, 'sendEmail'=>0));
More info here. Hope that helps :)
Answered By - Criesto
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.