How do I make a list (just products names and links) of random products on the right column of my site? Also, how do I list all products according to A-Z in a separate page?
Thanks
Hi David,
Thanks for the quick reply. I'm using your code. It's only showing one product though. see http://tinyurl.com/2udad6
Hi,
My mistake - the print line was outside the loop, so it was only printing the last product selected! I've moved it to the correct place, and also added $config_baseHREF to the URLs which will be required to make sure it works on other pages...
All corrected in the code above now.
Cheers,
David.
Hi,
The code to select random products and display a list of links is as follows:
<?php
$sql = "SELECT name FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 5";
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$href = $config_baseHREF."products.php?q=".urlencode($product["name"]);
}
print "<p><a href='".$href."'>".$product["name"]."</a></p>";
}
}
?>
It sounds like you may already have the right hand column created - but if not you can do this via CSS, or by creating table code with the top of the table and left column(s) started in html/header.php, and then the right hand column and end of the table in html/footer.php. There's some code for doing this in the following thread:
http://www.pricetapestry.com/node/565
Bear with me on the all products A-Z and help you out with code for that shortly...
Cheers,
David.