nublet Posted January 27, 2009 Share Posted January 27, 2009 Hi im trying to arrange images into neat rows but im not sure how to go about it. This is the code im using to display pictures at the moment but it just gives me a long column of pictures. <?php include("config.inc.php"); $result = mysql_query("SELECT * FROM gallery_photos"); While($row = mysql_fetch_array($result)){ echo "<a href='photos/" . $row['photo_filename'] . "'><img src='photos/tb_" . $row['photo_filename'] . "' border='1' /></a><br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/142695-arranging-images-into-rows/ Share on other sites More sharing options...
bluesoul Posted January 27, 2009 Share Posted January 27, 2009 <?php include("config.inc.php"); $result = mysql_query("SELECT * FROM gallery_photos"); $i = 0; While($row = mysql_fetch_array($result)){ if($i == 3) { echo "<br />"; $i = 0; } //change 3 to however many you want per row echo "<a href='photos/" . $row['photo_filename'] . "'><img src='photos/tb_" . $row['photo_filename'] . "' border='1' /></a>"; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/142695-arranging-images-into-rows/#findComment-747944 Share on other sites More sharing options...
xangelo Posted January 27, 2009 Share Posted January 27, 2009 <?php include("config.inc.php"); $pics_per_row = 5; $result = mysql_query("select * from gallery_photos"); $inc = 0; echo '<table>'; while($row = mysql_fetch_array($result)) { if($inc%$pics_per_row == 0) { echo '<tr>'; } echo '<td><a href="photos/' . $row["photo_filename"] . '"><img src="photos/tb_' . $row["photo_filename"] . '" border="1" /></a><br /></td>'; if($inc%$pics_per_row == 0) { echo '<tr>'; } $inc++; } echo '</table>'; Link to comment https://forums.phpfreaks.com/topic/142695-arranging-images-into-rows/#findComment-747946 Share on other sites More sharing options...
nublet Posted January 27, 2009 Author Share Posted January 27, 2009 Thanks for the quick replies. How would i got about spacing the images evenly and centering them in the page? Is it fine to do that with php or is it better doing things like that with css? xangelo I tried your code but it made the pictures go in a strange order like rows of 1 then 4 then 1 then 3 I coudnt work out why that was happening though. Link to comment https://forums.phpfreaks.com/topic/142695-arranging-images-into-rows/#findComment-748002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.