Ah, the old columns and rows conundrum!!!
In the past, I've handled this using remainder division (mod or %)
For example, if I want at most 3 rows with two columns:
<?php
$q5 = "SELECT * FROM pictures WHERE property_id=$id LIMIT 6";
$r5 = @mysqli_query ($dbc,$q5);
echo '<P>
<h1>Additional Pictures</h1>
<table class="flyer" cellpadding="20" cellspacing="0" align="center" width="100%"><tr>';
while ($row = mysqli_fetch_array ($r5, MYSQLI_ASSOC)) {
echo '<td align="center">
<table class="listing" cellpadding="0" cellspacing="0" align="center" width="50%"><td>
<img src="../../uploads/details/'.$row['pic_url'].'" width="230">
</td></table>
</td>';
// when counter variable divided by 2 and the remainder is zero, start new row.
echo ( ++$counter % 2 == 0 ) ? "</tr><tr>" : "";
}
echo ' </tr></table>';
?>
However, this can be tricky (I haven't taken a great deal of time to make this work good for your layout. If you choose this method, you may need to adjust it slightly) For example, I can end up with an empty row "</tr><tr></tr>". Thus, I think the best way to do this is to separate the layout from the coding completely. And yes, that means css.
<style type="text/css">
.container {
width:500px;
}
.image {
width:245px;
float: left;
}
</style>
<?php
$q5 = "SELECT * FROM pictures WHERE property_id=$id LIMIT 6";
$r5 = @mysqli_query ($dbc,$q5);
echo '<P>
<h1>Additional Pictures</h1>
<div class="container">';
while ($row = mysqli_fetch_array ($r5, MYSQLI_ASSOC)) {
echo '<div class="image"><img src="../../uploads/details/'.$row['pic_url'].'" width="230"></div>';
}
echo '</div>';
?>
Basically, the layers of class "image" with a width of 245 (image has width of 230) float left until they are forced below by the "container" layer through constraining to 600px; You may have to adjust the widths, but this method is not only easier, it's more practical.
Cheers!