asuming $res holds your query result:

echo '<table>';
while($img=mysql_fetch_array($res)) {
   if($col==0) echo '<tr>';
   echo "<td> <img src="$img[thumb]"> </td>";
   if($col==4) {
       echo '</tr>';
if($col!=0) str_repeat('<td></td>', 4 - $col);
echo '</table>';

Not tested

Wee Keat [Amorphosium] wrote:

Hi all...
I've tried to figure this one out but I'm really having a headache now. So, I really need your help.


I have a database of images and its own thumbnails created using GD. It worked wonderfully.


I want to display ONLY thumbnails in table form, incrementing in rows of 4 columns. By this I mean that I want to write a script which loops in a way that it displays 4 pictures withdrawn from the database into a row, and then for the next 4 images, displays them into the next row.

If you don't understand see the gif below... a script that displays 4 pictures across first ( arrow 1) , then goes to the next row and displays the next 4 ( arrow 2).

I can't work out how can i structure my loop to do this.


Can all the gurus out there please give me a pointer? I really can't work out the logic or systematic flow of scripting this one.

Thank you so much in advance!


Wee Keat Chin

"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." - Albert Einstein

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to