tags:

views:

52

answers:

3

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 ,

A: 

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.

jeroen
+2  A: 
  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>';
dev-null-dweller
what is the logic should i use, to display next and back link, so far i used just pager class for my paginations
Bharanikumar
I've edited the code to show the logic. Just check if current page is first or last, and increase or decrease page number in your links.
dev-null-dweller
but query string going negative and also next link missing in some situtaion
Bharanikumar
@Bharanikumar Write a condition to prevent this. Are you a programmer or what?
Col. Shrapnel
yes programer...
Bharanikumar
A: 

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

Sabeen Malik