Re: How to loop diplays of 4 column of items, every row?
| From: | Marek Kilimajer | Date: | Fri, 06 Dec 2002 13:49:18 +0000 |
| Subject: | Re: How to loop diplays of 4 column of items, every row? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-127252@lists.php.net to get a copy of this message | ||
asuming $res holds your query result:
$col=0;
echo '<table>';
while($img=mysql_fetch_array($res)) {
if($col==0) echo '<tr>';
echo "<td> <img src="$img[thumb]"> </td>";
$col++;
if($col==4) {
echo '</tr>';
$col=0;
}
}
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. Situation: I have a database of images and its own thumbnails created using GD. It worked wonderfully. Problem: 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. Question: 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! Yours, Wee Keat Chin ------------------------------------------ "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." - Albert Einstein