我需要使用yii
上的where子句,在我的代码下面,我需要添加where activated == 0 && send_email == 0
。
$model = User::model()->findAll();
谢谢
答案 0 :(得分:2)
有多种方法可以做到这一点:
$model = User::model()->findAll('activated=0 AND send_email=0');
或者,
$model = User::model()->findAll('activated=:activated And send_email=:sendEmail',
array(':activated'=>0,':sendEmail'=> 0));
或者,
$criteria = new CDbCriteria;
$criteria->condition='activated=:activated AND send_email=:sendEmail';
$criteria->params=array(':activated'=>0,':sendEmail'=>0);
$model=User::model()->findAll($criteria);
或者,
$model = User::model()->findAllByAttributes(array('activated'=>0, 'send_email'=>0));
或者,
$model = User::model()->findAllBySql('SELECT * FROM user WHERE activated=:activated AND send_email=:sendEmail', array(':activated'=>0, 'sendEmail'=>0));
更多信息here。希望有所帮助:)
答案 1 :(得分:1)
试试这个:
$model = User::model()->findAll(array("condition"=> "activated=0 AND send_email=0"));