Kamerov
Kamerov

Reputation: 129

How do I paginate images with PHP?

I'm trying to paginate an arbitrary number of photos that I'm getting from a image directory onto my web page.

Here is my PHP script I'm running thus far:

<?php
    $dir = "images/";
    $counter = 1;
    if($opendir = opendir($dir)){
        //read directory
        while(($file = readdir($opendir)) !== FALSE){
            if($file != "." && $file != ".."){
                echo "<img src='$dir/$file' alt='Picture broken' style='border-style: solid;border-width: 2px;border-color: #4d94ff; margin: 5px'>";
                $counter++;
            }
        }
    }
    echo "<p>There are $counter images</p>";
?>

How do I get this to paginate automatically with 10 images on each page?

Upvotes: 0

Views: 172

Answers (1)

M Maavia
M Maavia

Reputation: 340

save all your images name of specific directory in a global array and paginate it with you own will :)

Upvotes: 1

Related Questions