Displaying only 10 images from folder

Hi all,

Can someone give me idea how to display only 10 images from a folder ? like on a site when we have too many images, the page is divided into lets say 3 more pages like this

1 2 3 >

How can i do this ?

Well, each page is given a page number somehow, or default to 1, such as:


It should get a list of the images from the directory and then only select a chunk of items ($Page10) to (($Page10) + 9). Of course, it depends how you retrieve those items - in a database containing the image information (the best approach IMO) it’d be quite easy. If you’re just relying on the filesystem it depends on your naming conventions whether or not it can be made to still be efficient with a few thousand images.

If you name the images ‘image1.jpg’, ‘image2.jpg’ then you could simply do a loop and get the $ith image for $i in range($Page * 10, ($Page * 10) + 9), however if you don’t have a good naming scheme then you’ll have to get all of the image paths into an array (one which will always be in the same order) and then use array_slice to grab 10 images from the correct part of that array.

I assume you are talking about “pagination”?

Google pagination will turn up quite a few good tutorial on the subject. For example, this one is at the top of the list:

Exactly! it’s very simple for beginner.