Lucky2710 Posted November 22, 2010 Share Posted November 22, 2010 Im working on a site and particularly the photo gallery section. I want to display 9 images on 3 rows (3 per row). And im stuck. Te only way i can get the images to show up not one on top of the other is by using a table. but how can i tell the table to only put 3 <td>'s then to <br> Heres my code so far... <?php $sql_images = mysql_query("SELECT * FROM photos ORDER BY upload_date DESC LIMIT 9"); while($row = mysql_fetch_array($sql_images)){ $photo_id = $row["id"]; $location = $row["location"]; $display_pics .= ' <td width="125px"> <a href="image.php?id='. $album_id .'" class="black"><img src="images/uploads/thumbs/' . $location . '" /></a> </td>'; } ?> Then to display it ... <table width="top" cellpadding="10" cellspacing="20"> <tr> <?php echo $display_pics; ?> </tr> </table> My goal is to do it as simple as possible! Can anyone help? If you don't think tables are the way to go im open to any suggestions. I've thought about <divs> but then the images show up one on top of the other and not beside each other. By the way all the images are a max of 100px heigh and 100px wide Thanks for any help or suggestions! Link to comment https://forums.phpfreaks.com/topic/219410-dynamic-rows/ Share on other sites More sharing options...
Garethp Posted November 22, 2010 Share Posted November 22, 2010 <table> <?php $i = 0; while($Row = mysql_fetch_array($Query)) { echo "<td>{$Row['Data']}</td>"; $i++ if($i == 3) { echo "</tr><tr>"; $i = 0; } } ?> </table> Link to comment https://forums.phpfreaks.com/topic/219410-dynamic-rows/#findComment-1137726 Share on other sites More sharing options...
revraz Posted November 22, 2010 Share Posted November 22, 2010 From the FAQ http://www.phpfreaks.com/forums/faqcode-snippet-repository/multi-column-results/ Link to comment https://forums.phpfreaks.com/topic/219410-dynamic-rows/#findComment-1137727 Share on other sites More sharing options...
Lucky2710 Posted November 22, 2010 Author Share Posted November 22, 2010 Thanks for the help i got it now Link to comment https://forums.phpfreaks.com/topic/219410-dynamic-rows/#findComment-1137735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.