ll87 Posted November 19, 2009 Report Share Posted November 19, 2009 I found this guide on how to create a paginated image gallery in PHP. I have adapted it to suit my needs, but there is one bit which is completely stumping me. I reckon you'd have to read it all to be able to help me, so please do, if you have the time: http://www.lateralcode.com/simple-php-gallery-pagination/ The bit which is confusing me is: $count = 0; $skip = $page * $per_page; while ( $count < $skip && ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) $count++; } the reason is, on the next line, it resets $count to 0, so the above loop to me seems pointless. I took it out and re-ran the code and it breaks so it is needed. But all it does is increment count until count equals skip and then it is reset on the next line anyways. i think the main reason im getting so confused is that the article isn't explaining it wel enough, perhaps because they don't expect the reader to be a noob, ha. help me someone please . Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted November 19, 2009 Report Share Posted November 19, 2009 That snippet is used to have the script bypass/skip the first batch of images when you are not on page one. $skip is the number of images that it should bypass. It reads the images in a directory and uses the $count variable to compare to the $skip variable. When $count equals $skip, the Images you want to display are the next ones in the Directory. Quote Link to comment Share on other sites More sharing options...
ll87 Posted November 19, 2009 Author Report Share Posted November 19, 2009 but i dont see how, because it's not doing anything with the updated $count variable? where does it use that to ensure the next batch of images are loaded? thanks for your help Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted November 20, 2009 Report Share Posted November 20, 2009 what that snippet of code is doing is reading the contents of the Folder and skipping the ones you do not wish to show (because they are on earlier pages). Once the correct number of images has been reviewed, (and ignored), the script resets the counter and displays the next page of images. It uses the $counter to seek the spot to begin displaying the pages. Quote Link to comment Share on other sites More sharing options...
ll87 Posted November 23, 2009 Author Report Share Posted November 23, 2009 how does it display the next set of images? a block echo-ing some html img tags does not directly follow this snippet, so i dont understand how it displays the next set. i understand what your saying it SHOULD be doing, but it still doesn't make sense looking at what code is actually there. seems like there is something missing Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted November 24, 2009 Report Share Posted November 24, 2009 the portion of the script that you don't list above which follows the script snippet you list is what does the displaying of the images for the thumb gallery >while ( $count if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { if ( ! is_dir('thumbs') ) { mkdir('thumbs'); } if ( ! file_exists('thumbs/'.$file) ) { makeThumb( $file, $type ); } echo '</pre> <li>'; echo ''; echo '</li>';<br> $count++;<br> 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.
Note: Your post will require moderator approval before it will be visible.