PHP pagination: is_dir is truncating images when looping through readdir
<p>I just got pagination to work on my site, but I wanted to use a thumbnailer script that accepts a path, not a resource. This conflicts with how I pagination- using readdir to scan for a resource.</p>

<p>Right now I'm implementing a skip pattern I found online to keep track of images and their corresponding page numbers:</p>

<pre><code>while ( $count &lt;= $skip &amp;&amp; ($file = readdir($handle)) !== false ) {
            if ( !is_dir($file))
                $count++;
        }

        $count = 0;
</code></pre>

<p>So,</p>

<p>Question 1) This method sets $count = 0 after it's run, so I don't see how it can be useful for the rest of the script.</p>

<p>Question 2) This part actually displays the correct images on page according to page number. I set $imagesPerPage = 4, so 4 should display on all pages. But, since I'm doing  an !is_dir check, it's truncating those first two items (which are directories . and ..), but it's not refilling those spots with actual images (bec all pages except the last page should have 4 images on them...)</p>

<pre><code>while ( $count++ &lt; $imagesPerPage &amp;&amp; ($file = readdir($handle)) !== false ) {
            if(!is_dir($file)) {
            $image = $imagePath . $file;
        ?&gt;
            &lt;a href="../templates/viewComic.php?image=&lt;?php echo $image ?&gt;"&gt;&lt;img src="../scripts/thumbnailer2.php?img=&lt;?php echo $image ?&gt;" /&gt;&lt;/a&gt;  

        &lt;?php
            }   
        }
</code></pre>

<p><img src="http://i.stack.imgur.com/OecD5.jpg" alt="enter image description here"></p>

<p>Question 3) How can I get the pages to begin on 1 instead of 0? </p>

<p>Any help in understanding would be appreciated!</p>
