我想從兩個表商店和mmm_store_services獲取數據是,除了這個警予Cdbcriteria不能正常工作
if(isset($_POST['Store']['location']) && !empty($_POST['Store']['location'])){
$conditions[] = ' AND t.location = '.$_POST["Store"]["location"];
}
這裏做工精細的所有條件,就是我全部的代碼
$criteria=new CDbCriteria;
$conditions = array();
if(isset($_POST['Store']['category']) && !empty($_POST['Store']['category'])){
$conditions[] = ' AND mmm_store_services.category_id ='.$_POST['Store']['category'];
}
if(isset($_POST['Store']['sub_category']) && !empty($_POST['Store']['sub_category'])){
$conditions[] = ' AND mmm_store_services.service_id ='.$_POST['Store']['sub_category'];
}
if(isset($_POST['Store']['location']) && !empty($_POST['Store']['location'])){
$conditions[] = ' AND t.location = '.$_POST["Store"]["location"];
}
if(isset($_POST['Store']['price']) && !empty($_POST['Store']['price'])){
$price = explode('-',$_POST['Store']['price']);
$minPrice = trim($price[0]);
$maxPrice = trim($price[1]);
$conditions[] = ' AND mmm_store_services.price between '.$minPrice.' AND '.$maxPrice;
}
if(count($conditions)>0){
$condition = implode(' ',$conditions);
$criteria->join.='INNER JOIN mmm_store_services ON mmm_store_services.store_id = t.id '.$condition;
}
$criteria->compare('t.approve','Y');
$model = new CActiveDataProvider('Store', array(
'criteria'=>$criteria,
'pagination'=>array('pageSize'=>'2'),
));
請給我一個解決方案。 謝謝。
'$ conditions'是否必須位於'WHERE'部分? – Justinas 2014-09-25 06:40:48
那我該怎麼辦? – aman 2014-09-25 06:46:08