Jump to content

[SOLVED] alignment issue


zang8027

Recommended Posts

maybe this is more HTML problem than PHP but it involves PHP so here it is

 

Im doing a website that loads in images from a database. Im using a table to align them. Here is my code:

 

<?php

print "<tr>";


while($row = mysql_fetch_array($result)){

//store into a variable the pic image
$pic=$row['bottle_pic'];


//display the row data using the variables from above
 	print "<td><img src='images/purecane/$pic'></td>";

}
print"</tr>";

?>











 

 

the problem with this is that my table stretches across my site, rather than doing like.. a line break. I gave my div tag a set width but it didn't do anything. Whats the best way to get, say 3 pictures to show up beside each other, then line break and do the same thing under it?

 

Link to comment
https://forums.phpfreaks.com/topic/112854-solved-alignment-issue/
Share on other sites

make a max colums variable:

<?php
$columns = 0;
print "<tr>";


while($row = mysql_fetch_array($result)){
//store into a variable the pic image
$pic=$row['bottle_pic'];


//display the row data using the variables from above
 	print "<td><img src='images/purecane/$pic'></td>";

}
print"</tr>";
if ($columns == 3)
{
	echo "<tr>";
	$columns = 0;
}
else
	$columns++;


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.