Hi There,
I current have the random function selecting 18 products on my front page, however due to some merchants having 1000's of products and some only having a few, these few seem to always miss out on appearing as random.
Can i alter the code to select 1 random product from each merchant? (limited to 18)
Thanks
Richard
hi,
that line through up the following errors
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/onestopo/public_html/includes/database.php on line 21
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/onestopo/public_html/includes/database.php on line 26
Thanks
Hi Richard,
Try this version;
$sql = "SELECT DISTINCT(merchant),name FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 18";
Cheers,
David.
Hi Richard,
This can be done using the MySQL's DISTINCT function. Assuming that you now have a line similar to the following:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 18";
...try changing the query as follows:
$sql = "SELECT *,DISTINCT(merchant) AS dmerchant FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 18";
That should do the trick...
Cheers,
David.