I have a query which fetches some data from existing opencart web shop database.
The small problem are the doubled results which i solved locally using DISTINCT. It worked perfectly until i used the query online on my wordpress site. The results are doubled again, no matter the use of distinct.
The only difference in usage is that locally i used mysql() queries within a plain php document, however online i used $wpdb sentences inside the wordpress sidebar file.
Database is the same.
Local:
$preq = "
SELECT DISTINCT
product.product_id as proid,
product.image as proimg,
product_description.name as proname
FROM
product, product_description
WHERE
product_description.product_id = product.product_id
AND FIND_IN_SET(product.product_id, ( SELECT value FROM setting where `key` = 'featured_product' ) )
";
if($res=mysql_query($preq)) {
while ($rss = mysql_fetch_array($res)) {
echo $rss['proid'];
echo "<br/><br/>";
}
}
Online:
$mydb= new wpdb(/connection info/);
$rows = $mydb->get_results(
"
SELECT DISTINCT
product.product_id as proid,
product.image as proimg,
product_description.name as proname
FROM
product, product_description
WHERE
product_description.product_id = product.product_id
AND FIND_IN_SET(product.product_id, ( SELECT value FROM setting where `key` = 'featured_product' ) )
"
);
echo "<div id='fp_content'>";
foreach ($rows as $obj) {
echo $obj->proid;
echo '<br/>';
}
echo "</div>";
Everything works fine except of the duplicates.
Results:
Locally:
Values in "value" column: 28,40,42,43,46,47,49
Results:
28
40
42
43
46
47
49
----------------------
Online:
Values in "value" column: 50,51,52
Results:
50
50
51
51
52
52