How do I do an IN query?

Basically I'm try to:

<code>

$condition_text .= "statusId IN (:statuses) ";

$Criteria->params[':statuses'] = implode(",", $this->IssueSearchForm->statuses);

</code>

However it only seems to be looking at my first value.  Any ideas why this would happen?

What is the way to use "SELECT * FROM projects WHERE statusId IN (2,3,4,5)" using the CDbCriteria?

Thanks.

hi

try :






$criteria=new CDbCriteria;





$ids = array(2,3,4);





$place_holders = array();





foreach($ids as $id) {


			


	array_push($place_holders,':id_' . $id);


	$criteria->params[':id_' . $id] = $id;


		


}





$criteria->condition = 'statusId IN ('. implode(',',$place_holders) .')';





YourModel::model()->findAll($criteria);





hope this helps

Assuming your model is called 'Projects', the only way I could get this to work was



$statuslist = $this->IssueSearchForm->statuses;


$db=Projects::model()->dbConnection;





$condition=$db->commandBuilder->createInCondition(Projects::model()->tableSchema, 'statusId',$statuslist); 





$result = Projects:model()->findAll($condition);


Hope this helps.  :)

Aiden.

Thanks to both of you.

I was able to get this working simply doing this: (Since I'm only dealing with integers, going out of my way to bind the list of many possible status keys seemed to be overkill)

foreach($statuses AS $key => $status) {

  $statuses[$key] = (int) $status;

}

$imploded = implode(",", $statuses);

$Criteria->condition = "statusId IN ($imploded)";

So I may go your route, but this is a 'Simple' way to do it.