zang8027 Posted July 1, 2008 Share Posted July 1, 2008 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? Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 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++; ?> Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 1, 2008 Share Posted July 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
zang8027 Posted July 2, 2008 Author Share Posted July 2, 2008 awesome, i used the column variable Thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.