php pagination without database
How to create pagination script with out data开发者_开发百科base 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 ,
- Put all files into an array
- 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>';
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.
You can read all of the image names in the directory into an array, maybe using opendir
. Then use this array as your database.
精彩评论