images from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
amirbwb
Forum Commoner
Posts: 89
Joined: Sat Oct 30, 2010 6:10 pm

images from database

Post by amirbwb »

hello i want to display 9 images from my database ...
actually everything is fine but i want to display them : each 3 images on a row and leave space beween them:
ex:
[ ] [ ] [ ]

[ ] [ ] [ ]

[ ] [ ] [ ]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: images from database

Post by califdon »

So what is your question?? Do remember, this is a PHP Code forum.
User avatar
amirbwb
Forum Commoner
Posts: 89
Joined: Sat Oct 30, 2010 6:10 pm

Re: images from database

Post by amirbwb »

califdon wrote:So what is your question?? Do remember, this is a PHP Code forum.
my quest is howwwwwwwwwwwww to display each 3 images on a row!!!!!!!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: images from database

Post by califdon »

amirbwb wrote:
califdon wrote:So what is your question?? Do remember, this is a PHP Code forum.
my quest is howwwwwwwwwwwww to display each 3 images on a row!!!!!!!
PHP is a server-side language and plays no part in displaying anything in a browser. If you need to know how to arrange your web page, you should post your question in a forum that deals with HTML. If you already understand how to arrange your web page, then I don't understand why you are asking how to do it.
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: images from database

Post by s992 »

This example will give you a result of
[a1][a2][a3]
[b1][b2][b3]
[c1][c2][c3]

but it will also contain an extra empty <tr></tr> at the bottom of the table. You should be able to work with this to get what you need.

Code: Select all

<?php
$arr = array("a1","a2","a3","b1","b2","b3","c1","c2","c3");

echo "<table><tr>";
$count = 1;

foreach($arr as $cell) {
	if($count % 3 == 0) {
		echo "<td>$cell</td></tr><tr>";
		$count++;
	} else {
		echo "<td>$cell</td>";
		$count++;
	}
}
echo "</tr></table>";
?>
Post Reply