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
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++;


?>

Link to comment
Share on other sites

say we are doing a total of 9 images

 

<table>
<tr>
<?php
for($x=0;$x<=8;$x++
{
echo(PHP_EOL."<td>".PHP_EOL."<img src='images/purecane/".$pic."'>".PHP_EOL."</td>");

if($x=2||$x=6)
{
echo(PHP_EOL."</tr>".PHP_EOL."<tr>".PHP_EOL);
}
}

?>

</tr>
</table>

 

something like that

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.