blueberrylolli Posted September 6, 2009 Share Posted September 6, 2009 I found this tutorial for php gallery with pagination at (http://www.lateralcode.com/simple-php-gallery-pagination/). It sorts the images according to time, so someone wrote a note about how to sort the files according to name here (http://www.lateralcode.com/reading-directories-in-sequence-in-php/). I tried combining the two code with the following function getPictures() { global $page, $per_page, $has_previous, $has_next; if ( $handle = opendir(".") ) { $files = array(); $lightbox = rand(); echo '<ul id="pictures">'; $count = 0; $skip = $page * $per_page; if ( $skip != 0 ) $has_previous = true; while ( $count < $skip && ($file = readdir($handle)) !== false ) { $files[] = $file; } sort($files); foreach ( $files as $file ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) $count++; } $count = 0; while ( $count < $per_page && ($file = readdir($handle)) !== false ) { $files[] = $file; } sort($files); foreach ( $files as $file ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { if ( ! is_dir('thumbs') ) { mkdir('thumbs'); } if ( ! file_exists('thumbs/'.$file) ) { makeThumb( $file, $type ); } echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">'; echo '<img src="thumbs/'.$file.'" alt="" />'; echo '</a></li>'; $count++; } } echo '</ul>'; while ( ($file = readdir($handle)) !== false ) { $files[] = $file; } sort($files); foreach ( $files as $file ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { $has_next = true; break; } } } } But now the pagination ($per_page, image thumbnails per page) doesnt' work. It displays all the pictures in the folder, and when you click next page, it loops through the entire folder for images again. If I take out the sort code in this part while ( $count < $skip && ($file = readdir($handle)) !== false ) { $files[] = $file; } sort($files); foreach ( $files as $file ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) $count++; } The gallery still doesnt' show the correct number of images from $per_page, but on the second page, it won't loop through the entire folder. If I take out the sort code in this section while ( ($file = readdir($handle)) !== false ) { $files[] = $file; } sort($files); foreach ( $files as $file ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { $has_next = true; break; } } } The "Next Page" button disappears and it's just one page with all the images from the folder, ignoring $per_page again. Any help would be appreciated thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/173289-looping-problem-with-php-image-gallery/ Share on other sites More sharing options...
blueberrylolli Posted September 6, 2009 Author Share Posted September 6, 2009 bump :3 Quote Link to comment https://forums.phpfreaks.com/topic/173289-looping-problem-with-php-image-gallery/#findComment-913771 Share on other sites More sharing options...
RussellReal Posted September 6, 2009 Share Posted September 6, 2009 add me to AIM or MSN / RussellCrevatas or RussellonMSN@hotmail.com ^^ respectively Quote Link to comment https://forums.phpfreaks.com/topic/173289-looping-problem-with-php-image-gallery/#findComment-913772 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.