fighting duplicate query results please help
Posted: Wed Jul 10, 2013 5:17 pm
Hello all. I am writing somethink like similar products. Products are taking from database based on price range specified by administrator. Only problem with that is the query returns duplicate data. One product can be shown 2 or even more times. I tried to use SELECT DISTINCT, Group by in MySQL and array_unique function in PHP. Neither didn't work at all. What are some other ways to solve the problem? The code is below.
Code: Select all
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 p_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 p_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++;
}
}