View Single Post
  #1  
Old 12-26-2006, 03:11 AM
 
jordan0 jordan0 is offline
 

Advanced Member
  
Join Date: Oct 2003
Location: San Francisco, CA
Posts: 77
 

Arrow A Random Product Button!

Simple! I just spent the last hour figuring out how to do something that I was surprised not to have found on the forums.

I made a button that when clicked, sends the customer to a random product page. Thats it. Dead simple.

All you have to do is make a new file, randomProduct.php in your xcart root dir containing the following:

Code:
<?php require "./auth.php"; $rnd = rand(); $random_product = func_query("SELECT $sql_tbl[products].productid FROM $sql_tbl[products] WHERE $sql_tbl[products].forsale='Y' ORDER BY RAND(NOW()+$rnd) LIMIT 1"); header("Location: product.php?productid=".$random_product[0]['productid']); ?>

And then wherever you would like the button on your site, use the following in any .tpl:

Code:
<a href="{$xcart_web_dir}/randomProduct.php">Random Product!</a>

This works on my 4.0.18 install. Enjoy.
__________________
Jordan Sitkin
http://www.kitkraft.biz
X-Cart 4.0.18 [unix]
Reply With Quote