MIK
MIK

Reputation: 906

CDb criteria conditions

How to make the following SQL condition in CDbcriteria

$dbCommand = Yii::app()->db->createCommand("SELECT * FROM offer_events WHERE enddate >= '$now' AND title like '%$locationdet%' AND description like '%$locationdet%' ORDER BY id DESC ");

Upvotes: 0

Views: 103

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

You could try doing:

$criteria = new CDbCriteria();
$criteria->condition = 'enddate >=:enddate AND title LIKE :title AND description LIKE :description';
$criteria->params = array(
    ':enddate'=>$enddate, 
    ':title'=> '%' . $title . '%', 
    ':description' => '%' . $description .'%'
);
$criteria->order = 'id DESC';
$model = SomeModel::model()->find($criteria);

Upvotes: 1

Related Questions