JJohnsenDK Posted April 28, 2007 Share Posted April 28, 2007 hey im trying to run a while loop that puts in breaks (<br />) when 3 pictures have been displayed. <?php while($catListRow = mysql_fetch_array($searchQuery)){ echo "<p><a href='gallery.php?action=3&no=".$catListRow['download_id']."&cat=".$catListRow['download_cat']."'><img src='".$catListRow['download_url']."' height='100' alt='".$catListRow['download_title']."' /></a></p>"; } ?> as the code are at the moment it just prints out all the pictures in one long line. How do i get the script to put in a line break everytime 3 pictures have been printed? Link to comment https://forums.phpfreaks.com/topic/49122-solved-putting-in-line-breaks-in-a-while-loop/ Share on other sites More sharing options...
papaface Posted April 28, 2007 Share Posted April 28, 2007 <?php $_num = 0 while($catListRow = mysql_fetch_array($searchQuery)) { echo "<p><a href='gallery.php?action=3&no=".$catListRow['download_id']."&cat=".$catListRow['download_cat']."'><img src='".$catListRow['download_url']."' height='100' alt='".$catListRow['download_title']."' /></a></p>"; $_num++; if ($_num == 3) { echo "<br>"; } } ?> Untested Link to comment https://forums.phpfreaks.com/topic/49122-solved-putting-in-line-breaks-in-a-while-loop/#findComment-240679 Share on other sites More sharing options...
JJohnsenDK Posted April 28, 2007 Author Share Posted April 28, 2007 that wont work because there can be 13 or 100 pictures so that script you posted will only put in line breaks after the 3 first pictures.. any ohter suggentions? Link to comment https://forums.phpfreaks.com/topic/49122-solved-putting-in-line-breaks-in-a-while-loop/#findComment-240683 Share on other sites More sharing options...
snowdog Posted April 28, 2007 Share Posted April 28, 2007 Only one thing I would add. If you want to display more than 6 pictures and need more breaks then you need to reset the counter to 0 when you add the break. <?php $_num = 0 while($catListRow = mysql_fetch_array($searchQuery)) { echo "<p><a href='gallery.php?action=3&no=".$catListRow['download_id']."&cat=".$catListRow['download_cat']."'><img src='".$catListRow['download_url']."' height='100' alt='".$catListRow['download_title']."' /></a></p>"; $_num++; if ($_num == 3) { echo "<br>"; $_num = 0; } } ?> Snowdog Link to comment https://forums.phpfreaks.com/topic/49122-solved-putting-in-line-breaks-in-a-while-loop/#findComment-240684 Share on other sites More sharing options...
papaface Posted April 28, 2007 Share Posted April 28, 2007 ^^^ Good point, forgot about that. Link to comment https://forums.phpfreaks.com/topic/49122-solved-putting-in-line-breaks-in-a-while-loop/#findComment-240687 Share on other sites More sharing options...
JJohnsenDK Posted April 29, 2007 Author Share Posted April 29, 2007 Ahh yes ofcause... thanks for helping out Link to comment https://forums.phpfreaks.com/topic/49122-solved-putting-in-line-breaks-in-a-while-loop/#findComment-240923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.