Random Featured Products
As an FAQ, I just wanted to post an up-to-date "Random Featured Products" mod as the various pages currently found in the forum relate to an older version of the script.
It's straight forward to have random featured products in place of the list of featured products as configured in the administration area. The products are picked using this code from line 32 of index.php
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";Simply replace this with:
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 3";...changing the LIMIT of 3 to whatever number of random product you require.
However; there is a caveat; in that if you have a very large site with many thousands of products; this method may be too slow. In that case; an alternative is to first pick a random merchant, and then to pick the random products from that merchant. To use this version, replace the original code with:
$sql = "SELECT DISTINCT(merchant) AS merchant FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 1";
database_querySelect($sql,$result);
$merchant = $result[0]["merchant"];
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($merchant)."' ORDER BY RAND() LIMIT 3";Hi Phil,
Sure - the replacement SQL just needs to refer to `productsmap` rather than `products` - the field names are the same! For example:
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."productsmap` ORDER BY RAND() LIMIT 3";Cheers,
David.
--
PriceTapestry.com
Hi David
Would it be possible to amend the random featured mod to choose random products from my mapped products only?
regards
Phil Stone
www.buy24-7.net