Posted By

drock on 06/19/12



Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Yii: Using MySQL's IN condition with Active Record

 / Published in: PHP

When working with your model's search function or just grabbing some data with findAll, you can't add an IN condition to your condition clause. Fail: $criteria->condition = 'start=:startID AND end=:endID AND status IN (1,2,3)';

Instead, use addInCondition:

  1. $criteria = new CDbCriteria();
  2. $criteria->condition = 'start=:startID AND end=:endID';
  3. $criteria->params = array(':startID'=>$activeProfileID,':endID'=>$pageID);
  4. $criteria->addInCondition('status',array(6,7));
  5. $results = GraphEdge::model()->findAll($criteria);
  7. //OR
  9. $theEdge = new GraphEdge();
  10. $results = $theEdge->findAllByAttributes(array('start'=>$activeProfileID,'end'=>$pageID,'status'=>array(6,7)));

Report this snippet  


RSS Icon Subscribe to comments
Posted By: Jacky888 on August 5, 2018

nova launcher prime download app

Posted By: Pokemon on March 1, 2019

Many many thanks for the post open control panel windows 10 for batter working.

You need to login to post a comment.