2014-02-05 113 views
0

創建CDBcriteria如何FO類似查詢創建cdbcriteria:在警予

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

回答

1

您可以直接如下合格條件。

注意:這是一種方法。不是最終的解決方案。

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

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

你不覺得你應該換的條件在雙引號? –

+0

@Letmesee謝謝。更新我的代碼。 –

+0

+1現在看起來不錯:) –

1

你可以嘗試某事像這樣:

$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);