Question

Anyone Please help me in implementing Paging in my project. I have nearly hundred pictures in images folder. When the user clicks the gallery link, the page will be directed to gallery.php, where the pictures should be shown 10 by 10. Please help me i need solution soon.

Was it helpful?

Solution

You could pass a GET parameter through the URL like so:

http://yourserver.com/gallery.php?p=1

Where variable p represents the page number.

Then, inside your php script, have it calculate where to start looking inside the database. If you say you need to display 10 by 10, I am assuming 100 pictures per page. So

$limit = 100;
$start = $_GET['p'] * $limit - $limit;

Then your SQL query would be to select $limit entries from $start:

$sql = "SELECT * FROM `yourtphototable` LIMIT {$start},{$limit};";

and then have an html link to the naxt page:

$nextpage = $_GET['p'] + 1;
$link = '<a href="http://yourserver.com/gallery.php?p=' . $nextpage . '">Next</a>';

OTHER TIPS

If you're loading the pictures from a folder, it may be best to simply load the file names in as array-entries, and then show only 10 items from the array at a time, tracking your "page" (really your array start-index) via a $_GET variable in the address bar.

If you are using MYSQL, as the tag suggests, then you can pass the page they are on in the URL as Jonathan suggested, and GET is nice as it enables the user to jump to where they want to be, you can bookmark a favorite page, etc, and on the mysql side just make certain that you are then use the LIMIT command.

You can find some help on this page, btw: http://www.php-mysql-tutorial.com/wikis/php-tutorial/paging-using-php.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top