gpt4 book ai didi

php - 如何在 Yii CdBCriteria 中添加不同的外键和主键

转载 作者:行者123 更新时间:2023-11-29 00:09:12 26 4
gpt4 key购买 nike

我有两个表 store(id,name,date)store_services(id,store_id,name,price,date)我已按价格 实现搜索过滤器,我想在我的页面中显示独特的商店记录。但我仍然从存储表中获取重复记录。

通过 distinct(store_services.store_id) 在 mysql 查询中工作正常但它不适用于 Yii CDbCriteria。我的 Mysql 查询是:

SELECT DISTINCT(store_services.store_id),store.id,store.name,store.date FROM store INNER JOIN store_services ON store.id = store_services.store_id WHERE store_service.price BETWEEN 1,1000

请给我一个 Yii 不同记录的代码注意:我在 Yii 中使用 $criteria->distinct=true;

但它也得到了重复的记录

最佳答案

正在将 $criteria->distinct=true; 替换为 $criteria->group = 'store_id';

这是我的所有代码,希望有人能从中找到帮助。

        $criteria=new CDbCriteria;
//$criteria->distinct=true;
$criteria->group = 'store_id';
$criteria->select = 't.id,t.name,t.state,t.city,t.location,t.address,t.contact_no,t.email,t.facilities,t.profile_photo,t.description, t.merchant_id, t.approve, t.added_date';
$flag = false;

if(isset($_GET['Store']['category']) && !empty($_GET['Store']['category'])){
$criteria->compare('mmmStoreServices.category_id', $_GET['Store']['category']);
$flag = true;
}

if(isset($_GET['Store']['sub_category']) && !empty($_GET['Store']['sub_category'])){
$criteria->compare('mmmStoreServices.service_id', $_GET['Store']['sub_category']);
$flag = true;
}



if(isset($_GET['Store']['price']) && !empty($_GET['Store']['price'])){
$price = explode('-',$_GET['Store']['price']);
$minPrice = trim($price[0]);
$maxPrice = trim($price[1]);
$criteria->addBetweenCondition('mmmStoreServices.price', $minPrice, $maxPrice);
$flag = true;

}


if($flag){
$criteria->with = array('mmmStoreServices'); // Put `mmm_store_service` to relations of model 'Store'
$criteria->together = true; // Check if you really need this parameter!
}

if(isset($_GET['Store']['location']) && !empty($_GET['Store']['location'])){
$criteria->compare('t.location', $_GET["Store"]["location"]);
//$flag = true;

}


$criteria->compare('t.approve', 'Y');

$ajaxModel = new CActiveDataProvider('Store', array(
'criteria' => $criteria,
'pagination' => array('pageSize'=>'2'),
));

关于php - 如何在 Yii CdBCriteria 中添加不同的外键和主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26053737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com