Bharanikumar
Bharanikumar

Reputation: 25733

php pagination without database

How to create pagination script with out database support,

i have 200 images in my images folder,

i want to display these images with pagination ,

if DB means we use some count to we can create pagination , but its clearly mentioned no database, so how to create the pagination ,

Upvotes: 0

Views: 7635

Answers (3)

dev-null-dweller
dev-null-dweller

Reputation: 29462

  1. Put all files into an array
  2. Slice the array according to page number and number of pictures.

Exapmle code:

$images = glob('img/*.jpg');

$img_count = count($images);
$per_page = 10;

$max_pages = ceil($img_count / $per_page);

$show = array_slice($images, $per_page * intval($_GET['page']) - 1, $per_page);

if($_GET['page'] > 1)
    $prev_link = '<a href="images.php?page='.($_GET['page']-1).'"> previous </a>';
if($_GET['page'] < $max_pages)
    $next_link = '<a href="images.php?page='.($_GET['page']+1).'"> next </a>';

Upvotes: 2

Sabeen Malik
Sabeen Malik

Reputation: 10880

You can read all of the image names in the directory into an array, maybe using opendir. Then use this array as your database.

Upvotes: 0

jeroen
jeroen

Reputation: 91734

Just use glob() to read the directory, they your count is the length of the array returned by glob().

The rest would be the same as when you would use a database.

Upvotes: 0

Related Questions