Hello David,
What is the correct code to display random products for each category.
Firstly, i have created a new page ie html/menu1.php with the following:
<table>
<tr>
<td class='menu'>Clothing</td>
<td width='23px'></td>
<td class='menu1'>Shoes</td>
</tr>
<tr>
<td>Add Category Code</td>
<td width='23px'></td>
<td>Add Category Code</td>
</tr>
<br/>
<tr>
<td class='menu'>Books</td>
<td width='23px'></td>
<td class='menu1'>DVD</td>
</tr>
<tr>
<td>Add Category Code</td>
<td width='23px'></td>
<td>Add Category Code</td>
</tr>
</table>
Next i add this to default.css
.menu1 {
background: url(menubar.gif) repeat;
font-size: 14px;
font-weight:bold;
width:330px;
padding-left:10px;
height:30px;
padding-top:5px;
padding-right:10px;
padding-bottom:5px;
}
And lastly on index.php, i added
require("html/menu1.php");
What is the category code i need to add in for the above because i tried at first using for each merchant (as below) it gives me error.
<?php
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE merchant = 'Madam Shoes' ORDER BY RAND() LIMIT 1";
database_querySelect($sql,$products);
foreach($products as $product)
{
if ($product["image_url"])
{
$productHREF = $config_baseHREF."product/".str_replace(" ","-",$product["name"]).".html";
print "<td align='center' width='182'>";
print "</br>";
print "<a href='".$productHREF."' ><img width='120' height='120' border=0 src='".$product["image_url"]."' alt='".$product["name"] ."' /></a><br>";
print "</br>";
print "<font size=1> <a href='".$productHREF."'> ".$product["name"]."</a><br>";
print "</br>";
print $config_currencyHTML.$product["price"]." <br /></font>\n";
print "</br>";
?>
thanks
jack
Hello Jack,
Try something like this:
<?php
function randomProducts($category)
{
global $config_baseHREF;
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE category = '".database_safe($category)."' ORDER BY RAND() LIMIT 1";
if (database_querySelect($sql,$products))
{
foreach($products as $product)
{
$productHREF = $config_baseHREF."product/".str_replace(" ","-",$product["name"]).".html";
print "<a href='".$productHREF."'>".$product["name"]."</a>";
}
}
}
?>
<table>
<tr>
<td class='menu'>Clothing</td>
<td width='23px'></td>
<td class='menu1'>Shoes</td>
</tr>
<tr>
<td><?php randomProducts("Clothing"); ?></td>
<td width='23px'></td>
<td><?php randomProducts("Shoes"); ?></td>
</tr>
<br/>
<tr>
<td class='menu'>Books</td>
<td width='23px'></td>
<td class='menu1'>DVD</td>
</tr>
<tr>
<td><?php randomProducts("Books"); ?></td>
<td width='23px'></td>
<td><?php randomProducts("DVD"); ?></td>
</tr>
</table>
Cheers,
David.