murratw Posted April 20, 2012 Share Posted April 20, 2012 The code below works well and shows all the images in a folder in reverse chronological order. But I want to limit it to a certain number of images . This would enable me to have several pages of images. So the first page would display the latest 50 images, the second page would show 50-100, and the third, 100-150. Any helps on how to modify? I can create the pages manually. I just want to know how to limit the current page to a certain range. <?php //Your folder $files = glob("images/*.*"); function sortnewestfilesfirst($a, $b) { return filemtime($b) - filemtime($a); } usort($files, "sortnewestfilesfirst"); $colCnt=0; echo '<table border="0" style="width:1000px;">'; for ($i=0; $i<count($files); $i++) { $colCnt++; if ($colCnt==1) echo '<tr>'; echo '<td width="20%" style="font-size:8.5px; font-family:arial">'; $num = $files[$i]; echo ' <div class="ImgBorder"> <div class="clipout"> <div class="clipin"> <a href="' . $num . '" rel="lightbox[all]"><img class="thumb ImgBorder" src="'.$num.'"> </a> </div> </div></div>'." "; echo '</td>'; if ($colCnt==6) { echo '</tr>'; $colCnt=0; } } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/261309-simple-image-gallery-help/ Share on other sites More sharing options...
tipsmail7 Posted April 20, 2012 Share Posted April 20, 2012 You could use array and $_GET from PHP to accomplish your goal <?php //how many image per page? $img_per_page = 20; //default page $page = 1; //sanitize GET var if ((isset($_GET["page"])) && (is_int($_GET["page"]))) $page = $_GET["page"]; //Your folder $files = glob("images/*.*"); //max page possible $max_page = ceil(count($files) / $img_per_page); if ($page > $max_page) { echo "there is no page"; //or other warning } else { function sortnewestfilesfirst($a, $b) { //the rest of your code..... echo '</table>'; //add pagination for ($x = 1; $x <= $max_page; $x++) { echo "<a href='yourpage.php?page=$x'>[ $x ] </a>"; } } reference: http://www.w3schools.com/php/php_get.asp Quote Link to comment https://forums.phpfreaks.com/topic/261309-simple-image-gallery-help/#findComment-1339146 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.