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 Quote Link to comment 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++; } } ?> Quote Link to comment 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. =( Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 No problem, lol. 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.