View Single Post
  #40  
Old 07-19-2003, 09:19 AM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

Quote:
Originally Posted by davesphoto
I have got it working but I am doing the random part in the SQL query. My random.php is now:

Code:
<? // the database query $query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid ORDER BY RAND() LIMIT 2 "; // give the product array to smarty to make it available sitewide. $randoms = func_query($query); $smarty->assign("randoms",$randoms); ?>

This seems easy enough to me, are there any drawbacks to doing it this way?

I also added the original featured products back into the random.tpl so now I can specify one or two perminant featured products (with the X-cart module) and have two random ones.

Any other sugestions? This seems too easy compared to other solutions .

Nope you did it the more efficient way. Using mysql to do the random select and limit is way more efficient than the other methods.

Also means nothing heavy happens on the database

I was reading this thread and thinking why don't they just use the mysql ORDER BY RAND() LIMIT 10.

Saves on all the counting products, randomising seeds and stuff.

Nice one.

Note to others, using ORDER BY RAND() LIMIT in any sql statement will randomise your results for you. Very handy for having random offers/news/quote showing.
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote