在yii中创建CDBC标准
如何为查询创建cdbcriteria,如:在yii中创建CDBC标准,yii,yii-components,yii-events,Yii,Yii Components,Yii Events,如何为查询创建cdbcriteria,如: select * from table_name where 'profile_type'='*'OR 'profile_type'=$usertype AND 'location'='*'OR 'location'=$country 您可以直接通过以下条件 注:这是一种方法。这不是最终的解决办法 $criteria = new CDbCriteria; $criteria->condition = "(profile_type ='*'
select * from table_name where 'profile_type'='*'OR 'profile_type'=$usertype AND 'location'='*'OR 'location'=$country
您可以直接通过以下条件 注:这是一种方法。这不是最终的解决办法
$criteria = new CDbCriteria;
$criteria->condition = "(profile_type ='*' OR profile_type = $usertype) AND (location ='*' OR location = $country)";
$model = Model_name::model()->findAll($criteria );
你可以试试这样的东西:
$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 );
你不认为你应该用双引号把条件括起来吗?