You are here:  » Random Featured Products


Random Featured Products

Submitted by nazeelp on Sun, 2006-07-23 15:36 in

Is there any way to show 5 featured products randomly from the list of featured products.

Best Regards
Nazeel

Submitted by support on Sun, 2006-07-23 15:40

Hi Nazeel,

The featured products are selected with this code on line 32 of index.php:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";

To make it pick 5 random products from the list of featured products, change that line to the following:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY RAND() LIMIT 5";

Cheers,
David.

Submitted by rolli1 on Fri, 2006-10-27 10:06

Hi David,

I use this upper code, but I want to restrict the results to only 1 of 2 merchants. How can I manage that?

Regards

Roland

Submitted by blogmaster2003 on Mon, 2010-03-15 19:24

Sorry for bumping such an old thread but i want precisely this, i tried the edit but it seems the same products on the home page (where i have the featured products)

what should be the code to alter daily the products in a random way?

So users will see top 5 of the day or something like this.

Submitted by support on Mon, 2010-03-15 19:50

Hi,

If you want the same 5 products to be the "featured products of the day", changing at random daily (but staying constant in any 24hr period), you could do this as follows. Considering the latest distribution which I believe you are running; look for the following code on line 33 of index.php:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";

...and REPLACE that with:

  $seed = strtotime("Y-m-d",time());
  $sql = "SELECT *,1 AS sequence FROM `".$config_databaseTablePrefix."featured` ORDER BY RAND(".$seed.")";

Hope this helps!

Cheers,
David.

Submitted by blogmaster2003 on Wed, 2010-03-17 15:03

Well i tried it, but i still cant know if it will works. How can i put that to change hourly? So i will test and see in less time ;)

Submitted by support on Wed, 2010-03-17 15:05

Hehe

Try

$seed = strtotime("Y-m-d H:00:00",time());

Cheers,
David.

Submitted by blogmaster2003 on Thu, 2010-03-18 17:26

Hi

isnt working.

Im using the template revolution i bought on pricetapestrytemplates.com

Could be that???

Submitted by support on Thu, 2010-03-18 17:59

Hi,

I just noticed a mistake in the replacement code above, this line:

  $sql = "SELECT *,1 AS sequence FROM `".$config_databaseTablePrefix."featured` ORDER BY RAND(".$seed.")";

...should be:

  $sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` ORDER BY RAND(".$seed.") LIMIT 5";

That should be all it is...

Cheers,
David.