我正在尝试编写一个脚本,显示互联网商店中特定产品的其他产品。根据价格和类别显示的产品。例如,如果您选择主板脚本将向其显示硬盘冷却器ets的其他产品。价格范围必须由管理员指定。问题是代码返回重复的产品。我试过使用group by,在MySQL查询中有所不同。我也尝试在PHP中使用数组唯一函数。两者都没有奏效。什么可能解决这个问题?现在代码如下所示。
if(isset($product_info['related_kv4nt_id_2'])) {
$i=1;
$imax = 5;
while ($i < $imax) {
$product_sql_test2 = $this->db->query("SELECT p.product_id, p.price, pc.product_id AS product_id
FROM oc_product p
INNER JOIN oc_product_to_category pc ON p.product_id = pc.product_id
WHERE p.price BETWEEN '".$product_info['related_kv4nt_min_2']."' and '".$product_info['related_kv4nt_max_2']."'
AND pc.category_id = '".$product_info['related_kv4nt_id_2']."'
GROUP BY pc.product_id
ORDER BY RAND( )
LIMIT 0 , 10"); if(isset($product_sql_test2->row['product_id'])){$this->data['product_spec_2_'.$i.''] = $product_sql_test2->row['product_id'];}
$i++;
}
}
答案 0 :(得分:0)
尝试
GROUP BY product_id
或喜欢
GROUP BY p.product_id
pc.product_id AS product_id
将此更改为
pc.product_id AS p_id
并尝试分组
GROUP BY p_id