throwing thoughts out, I would use a table to format the way your row will look, then you can use a for/while/foreach loop to add a column.
You can be creative and do this
$i = 0;
while($row = mysql_fetch_array()) {
if ($i == 0) {
echo "<tr>";
}
echo "<td>" /* . image display code */ . "</td>";
$i++;
if ($i == 4) {
echo "</tr>";
$i = 0;
}
}
This should give you an idea of how to do it. The counter would control how you do columns and rows.
I'm a little tired, I hope this answers your question or gives a bit of guidance for you to complete your script.