thesecraftonlymultiply Posted April 22, 2008 Share Posted April 22, 2008 Hello everyone, How can I force a line break after 5 images have been displayed within this code? <?php // OPEN THUMBNAILS DIRECTORY $handle = opendir ('./thumbnails/'); while (false !== ($file = readdir($handle))) { // RECOGNISE FILES if($file != "." && $file != ".." && $file != basename(__FILE__)) { // PRINT THUMBNAIL IMAGE AND LINK TO EACH LARGER IMAGE FOR EVERY IMAGE FOUND print "<a href='./uploadedimages/{$file}' target='_blank'> <img src='./thumbnails/{$file}'></a>"; } } ?> Thanks alot, Luke Link to comment https://forums.phpfreaks.com/topic/102391-forcing-a-line-break-after-5-images-have-been-displayed/ Share on other sites More sharing options...
pocobueno1388 Posted April 22, 2008 Share Posted April 22, 2008 Like this: <?php // OPEN THUMBNAILS DIRECTORY $handle = opendir ('./thumbnails/'); $count = 0; while (false !== ($file = readdir($handle))) { // RECOGNISE FILES if($file != "." && $file != ".." && $file != basename(__FILE__)) { // PRINT THUMBNAIL IMAGE AND LINK TO EACH LARGER IMAGE FOR EVERY IMAGE FOUND print "<a href='./uploadedimages/{$file}' target='_blank'> <img src='./thumbnails/{$file}'></a>"; if ($count == 5){ echo '<br />'; $count = 0; } $count++; } } ?> Link to comment https://forums.phpfreaks.com/topic/102391-forcing-a-line-break-after-5-images-have-been-displayed/#findComment-524280 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Put this line BEFORE the while: $ctr = 0; Then, in the while, after the image is displayed, put this: if ($ctr == 5) { echo "<br />" $ctr = 0; } EDIT: Someone beat me to it. =( Link to comment https://forums.phpfreaks.com/topic/102391-forcing-a-line-break-after-5-images-have-been-displayed/#findComment-524281 Share on other sites More sharing options...
thesecraftonlymultiply Posted April 22, 2008 Author Share Posted April 22, 2008 Wow! Thankyou very much! This forum and its members are amazing! Thankyou, both of you Link to comment https://forums.phpfreaks.com/topic/102391-forcing-a-line-break-after-5-images-have-been-displayed/#findComment-524283 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 No problem, lol. Link to comment https://forums.phpfreaks.com/topic/102391-forcing-a-line-break-after-5-images-have-been-displayed/#findComment-524284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.