我有一个返回重复结果的查询。这里是:
$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");
我曾尝试使用 array_unique 函数,但它什么也没做。可以做些什么?
Ps 我以前问过类似的问题,但没有得到答案,链接是: previous question with full source code。
最好的问候波格丹
现在pps源代码
if(isset($product_info['related_kv4nt_id_2']))
{
$i=1;
$imax = 5;
while ($i < $imax)
{
$product_sql_test2 = $this->db->query("SELECT DISTINCT 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++;
}
}