i want to display a picture gallery by using a html table. the image id's are located in a mysql database so i need to call them and display them in multiple rows of the table. i want to display 5 pictures per row but the code i've written (shown below) is showing only 1 picture per row.

$query = "SELECT id FROM dynamicImages ORDER BY id DESC";
$result = mysql_query($query) or die(mysql_error());
while($input = mysql_fetch_array($result))
if(count($input)) { ?>
<table class="portfolio_table" cellspacing="0">
<?php for($i = 0; $i < count($input); ++$i) { ?>
<?php if(!$i) { ?>
<tr><?php } else if(!($i % 5)) { ?></tr>
<tr><?php } ?>
<td><img src="images/upload/dynamic/<?php echo $input[$i]; ?>.jpg" border="0" alt=""/></div></td>
<?php } ?>
<?php } ?>

please can somebody help???!!!