How to use 'IN (1,2,3)' with findAll?

前端 未结 2 549
不思量自难忘°
不思量自难忘° 2021-02-18 21:42

I need to get a couple of Students from the database, and I have their primary keys in a comma-separated string.

Normally using SQL it would be something like:



        
2条回答
  •  梦如初夏
    2021-02-18 21:52

    You can do it also that way:

    $criteria = new CDbCriteria();
    $criteria->addInCondition("id", array(1,2,3,4));
    $result = Student::model()->findAll($criteria);
    

    and use in array any values you need.

    Aleksy

提交回复
热议问题