yii 中的 findAll()

2022-01-04 00:00:00 php yii yii-cactiverecord

电子邮件存档表:

id email_id to from
1  101      uk  msm
2  102      uu  avc
3  101      rk  uk
4  103      xyz abc
5  104      xyz poi
6  104      abc xyz
7  101      xyz abc

现在在 Yii 中我想记录 email_id=101我正在使用下面的代码,但它不起作用.

Now in Yii I want record where email_id=101 I am using below code, but its not working.

$id =101;
$criteria = new CDbCriteria();
$criteria->addCondition("email_id < :email_id");
$comments = EmailArchive::model()->findAll($criteria, array(':email_id' => $id,));

推荐答案

尝试:

$id =101;
$comments = EmailArchive::model()->findAll(
array("condition"=>"email_id =  $id","order"=>"id"));

$id =101;
$criteria = new CDbCriteria();
$criteria->addCondition("email_id=:email_id");
$criteria->params = array(':email_id' => $id);
$comments = EmailArchive::model()->findAll($criteria);

$Criteria = new CDbCriteria();
$Criteria->condition = "email_id = $id";
$Products = Product::model()->findAll($Criteria);

相关文章