findAll() in yii

后端 未结 8 1022
日久生厌
日久生厌 2020-12-25 09:19

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 xy         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-25 09:38

    This is your safest way to do it:

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

    Note that if you comment out the commented lines you get a way to add more filtering to your search.

    After this it is recommend to check if there is any data returned like:

    if (isset($comments)) { // We found some comments, we can sleep well tonight
      // do comments process or whatever
    }
    

提交回复
热议问题