Submitted by multiz on Wed, 2007-05-09 23:01 in Price Tapestry
Hello,
It's been a long time since I've worked on this, but how would it be possible to put 5 random brands and categories on each product page -- using the footer file?
That's reasonably straight forward to do - here's some code to get you started:
<?php // 5 random brands print "<p>"; $q = sprintf("SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 5"); if (database_querySelect($q,$rows)) { foreach($rows as $product) { if ($config_useRewrite) { $href = $config_baseHREF."brand/".tapestry_hyphenate($product["brand"])."/"; } else { $href = $config_baseHREF."search.php?q=brand:".urlencode($product["brand"]).":"; } print "<a href='".$href."'>".$product["brand"]."</a> "; } } print "</p>"; // 5 random categories print "<p>"; $q = sprintf("SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 5"); if (database_querySelect($q,$rows)) { foreach($rows as $product) { if ($config_useRewrite) { $href = $config_baseHREF."category/".tapestry_hyphenate($product["category"])."/"; } else { $href = $config_baseHREF."search.php?q=category:".urlencode($product["category"]).":"; } print "<a href='".$href."'>".$product["category"]."</a> "; } } print "</p>"; ?>
Just add that to html/footer.php and away you go. You might want to modify the way it generates the HTML of course, but that's the framework you need...
Hi Michael,
That's reasonably straight forward to do - here's some code to get you started:
<?php
// 5 random brands
print "<p>";
$q = sprintf("SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products`
ORDER BY RAND() LIMIT 5");
if (database_querySelect($q,$rows))
{
foreach($rows as $product)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."brand/".tapestry_hyphenate($product["brand"])."/";
}
else
{
$href = $config_baseHREF."search.php?q=brand:".urlencode($product["brand"]).":";
}
print "<a href='".$href."'>".$product["brand"]."</a> ";
}
}
print "</p>";
// 5 random categories
print "<p>";
$q = sprintf("SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products`
ORDER BY RAND() LIMIT 5");
if (database_querySelect($q,$rows))
{
foreach($rows as $product)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."category/".tapestry_hyphenate($product["category"])."/";
}
else
{
$href = $config_baseHREF."search.php?q=category:".urlencode($product["category"]).":";
}
print "<a href='".$href."'>".$product["category"]."</a> ";
}
}
print "</p>";
?>
Just add that to html/footer.php and away you go. You might want to modify the way it generates the HTML of course, but that's the framework you need...
Cheers,
David.