Hey, im building a product catalogue web page which retrieve the info from mysql DB.
the idea is to have a table with 5 products in a row. each page got different number of product rows and the system dynamically create the rows.
I managed to work it out but… i still get some funny stuff going on.
The problem:
1. The first row starts with an empty undefined <td>.2. The last row contains some empty undefined <td> as well.
Please take a look at what ive achieved so far at:
(navigate to other products to see the problem on the other pages)
And the code i wrote is:
[code=php]
echo “<div id=”products”>”;
$query = “SELECT * FROM necklace ORDER BY ID”;
$result = mysql_query($query) or die (“Query failed”);
$num = mysql_num_rows($result); // = 37 total
$thumbcols = 4; // specify how many in each row
$thumbrows = 1 + round($num / $thumbcols);
echo “<form action=’$PHP_SELF’ method=’POST’><input type=’hidden’ name=’op’ value=’show’>”;
echo “<table>”;
function display_table(){
global $num, $result, $thumbrows, $thumbcols;
for($r=1; $r<=$thumbrows; $r++){
echo “<tr>”;
// format the number of columns to be printed in each row using a 2nd for loop
for($c=1; $c<=$thumbcols; $c++){
echo “<td class=”thumb”>”;
echo “<a href=’$PHP_SELF?op=show&code=$row[CODE]’><img src=”.$row[‘THUMB’].” border=”0″></img></a><br>”;
$row = mysql_fetch_array($result); // break out the array of values from the returned query
echo “</td>”;
}
echo “</tr>”;
}
}
display_table();
echo “</table>”;
echo “</form>”;
?>
Hope you guys can help me out.
Thanks, Shooka