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: 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>"; ?> PHP: Hope you guys can help me out. Thanks, Shooka
hi shooka, i think, ur 1st problem could be solved with reordering ur code lines a bit...try to instert line 19 somewhere earlier, like between line 16 and 17...$row needs to be defined to get a 'thumb' from it... ...2nd problem emerges because there r no more thumbs to show (37 thumbs) in your 10 row 4 column layout (40 cells)...so u can first check the row if it exists... i think this block should look something like that: for($c=1; $c<=$thumbcols; $c++){ $row = mysql_fetch_array($result); echo "<td class=\"thumb\">"; if (isset($row)) { echo "<a href='$PHP_SELF?op=show&code=$row'><img src=".$row['THUMB']." border=\"0\"></img></a><br>"; } else { echo " "; } echo "</td>"; } PHP: