[英]Create CDBcriteria in yii
如何为查询创建cdbcriteria,如:
select * from table_name where 'profile_type'='*'OR 'profile_type'=$usertype AND 'location'='*'OR 'location'=$country
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 );
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 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.