How To Return Results From Database Where A Column Matches A Value?

The code below returns all records from a database table.


    $criteria = array(

      'pagination' => array('pageSize' => 20),

      'sort' => array(

        'defaultOrder' => 'id DESC',

      ),

    );


    $dataProvider = new CActiveDataProvider('Step1', $criteria);

I need to modify it so it will only return records where a column matches a specific value. For example, only show records where "microsoft.com" is in the "site" column of the database.


    $criteria = array(

      ':site' => Yii::app()->params['src'],

      'pagination' => array('pageSize' => 20),

      'sort' => array(

        'defaultOrder' => 'id DESC',

      ),

    );


    $dataProvider = new CActiveDataProvider('Step1', $criteria);

Can someone tell me what I’m doing wrong?

Dear Friend

Kindly check this.




$criteria=new CDbCriteria;

$criteria->addSearchCondition("site",Yii::app()->params['src']);//assumed that column name is site.


$dataProvider = new CActiveDataProvider('Step1', array(

    "criteria"=>$criteria,

    "pagination" => array('pageSize' => 20),

    "sort" => array(

        'defaultOrder' => 'id DESC',)


));



Regards.

Thanks so much. That worked perfect!