Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

findAll() in yii

EmailArchive Table:

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

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,));
like image 891
User1988 Avatar asked Mar 16 '12 11:03

User1988


3 Answers

If you use findAll(), I recommend you to use this:

$data_email = EmailArchive::model()->findAll(
                  array(
                      'condition' => 'email_id = :email_id',
                      'params'    => array(':email_id' => $id)
                  )
              );
like image 67
Maharjan Avatar answered Oct 07 '22 10:10

Maharjan


Try:

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

OR

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

OR

$Criteria = new CDbCriteria();
$Criteria->condition = "email_id = $id";
$Products = Product::model()->findAll($Criteria);
like image 54
Sudhir Bastakoti Avatar answered Oct 07 '22 08:10

Sudhir Bastakoti


Just to add some alternate, you could do like this also:

$id =101;
$criteria = new CDbCriteria();
$criteria->condition = "email_id =:email_id";
$criteria->params = array(':email_id' => $id);
$comments = EmailArchive::model()->findAll($criteria);
like image 6
Arfeen Avatar answered Oct 07 '22 09:10

Arfeen