Gaurav Parashar
Gaurav Parashar

Reputation: 126

Create CDBcriteria in yii

How to create cdbcriteria fo the query like :

select * from table_name where 'profile_type'='*'OR 'profile_type'=$usertype  AND 'location'='*'OR 'location'=$country

Upvotes: 0

Views: 87

Answers (2)

Kumar V
Kumar V

Reputation: 8838

You can directly pass condition as below.

Note: This is one of the method. Not an ultimate solution.

$criteria = new CDbCriteria;
$criteria->condition  = "(profile_type ='*' OR profile_type = $usertype)  AND (location ='*' OR location = $country)";

$model = Model_name::model()->findAll($criteria );

Upvotes: 1

sakhunzai
sakhunzai

Reputation: 14470

you can try sth like this:

$criteria = new CDbCriteria;
$criteria->condition  = "(profile_type='*' OR profile_type=:prof ) AND 
                         (location='*' OR  location=:loc ) ";

$criteria->params = array(':prof' => $usertype, ':loc' => $country);

$model = MyModel::model()->findAll($criteria );

Upvotes: 1

Related Questions