Quite a while ago, I got this script to create a multiple column display for products.
x x x
x x x
x x x
like this or as many columns needed. The problem I am having with the script is when I put in the number I want for the column it doesn't properly display that number of columns, it basically ignors that column number and does what it wants.
then the second problem is sometimes it will continue to query even when there aren't any products, for example:
I have 16 products and with the current way the script is, which I will display at the end, 9 products are queried and they come out in a row 1 2 3 4 5 6 7 8 9 not in column form. If I change the $col place to 10 not 2, it will query all 16 products properly, but then it adds two extra blank fields at the end, so it show 18 places, 16 for actual products and two for empty. I have been playing with this script for a while and decided to put it out there to see if anyone can understand what may not be working properly or is someone has a better solution. This is the full script, minus my server information.
Thanks for any help.
Brett Taylor
$query = "SELECT ProductSku,
ProductName,
ProductImageThumbnail,
ProductCategory,
ProductPrice,
ProductSubCategory
FROM $table_A
WHERE ProductCategory = '$ProductCategory'
ORDER BY ProductName
";
$result = mysql_query($query);
$num=mysql_num_rows($result);
$col=2;
$total=$num/$col;
print"<table width=\"100%\" border=0 cellpadding=3 cellspacing=2>";
for($count=1; $count<$col; $count++) {
echo"<tr>";
for($count2=0; $count2<=$total; $count2++) {
echo"<td width=\"50%\" class=\"newclasses\" valign=\"top\" style=\"border:1 solid #cc9966;\" onmouseover=\"this.style.backgroundColor='#FFFFCC';\" onmouseout=\"this.style.backgroundColor='#ffffff';\">";
$row = mysql_fetch_array($result);
$ProductID = $row['ProductID'];
$ProductSku = $row['ProductSku'];
$ProductName = $row['ProductName'];
$ProductImageThumbnail = $row['ProductImageThumbnail'];
$ProductCategory = $row['ProductCategory'];
$ProductPrice = $row['ProductPrice'];
$ProductSubCategory = $row['ProductSubCategory'];
echo"<a href=\"product_detail.php?ProductID=$ProductID&ProductSku=$ProductSku\" class=\"listproduct\"><img src=\"graphics/$ProductImageThumbnail\" border=0 align=\"left\">
$ProductName
<br>\$$ProductPrice</a>";
echo"</td>";
}
print"</tr>";
}
print"</table>";
?>