Jump to content

PHP pagination


ll87

Recommended Posts

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 :(.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>               

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...