Post by bogdanus91 » 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++;

}
}

Newbie

Posts

Joined
Wed Jul 10, 2013 5:08 pm

Post by pedro1993 » Wed Jul 10, 2013 6:53 pm

What is related_kv4nt_id_2? What are you trying to achieve?

Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by bogdanus91 » Wed Jul 10, 2013 7:09 pm

Hello. The related products are divided in 4 categories defined by administrator. For example if I am choosing a video card I will see in my related products motherboards, Hard discs, cooling systems ets. That is defined by administrator too. The name $product_info['related_kv4nt_id_2'] is the category id in this case it is second category. While products are shown properly problem is that there are could be 2 absolutely same products with same price. I just need to avoid it from happening.

Newbie

Posts

Joined
Wed Jul 10, 2013 5:08 pm
Who is online

Users browsing this forum: No registered users and 90 guests