PS_Pagination is a flexible and easy to implement PHP pagination script which will help you split large result sets over multiple pages. Click here to download the script
The first step is to include the ps_pagination.php file in your script.
Create a ps_pagination object. The ps_pagination class constructor expects four parameters:
Next, call the paginate() function. This function returns a paginated result set for the current page. You can use this result set just as you would use a normal MySQL result set.
The final step is to display the pagination links. You can use the renderFullNav() function to generate and display the links in one go or you can use individual function calls to display each link separately.
<?php
//Include the PS_Pagination class
include('ps_pagination.php');
//Connect to mysql db
$conn = mysql_connect('localhost','username','password');
mysql_select_db('testdb',$conn);
$sql = 'select title from pages';
//Create a PS_Pagination object
$pager = new PS_Pagination($conn,$sql,8,3);
//The paginate() function returns a mysql
//result set for the current page
$rs = $pager->paginate();
//Loop through the result set
while($row = mysql_fetch_assoc($rs)) {
echo $row['title'];
}
//Display the navigation
echo $pager->renderFullNav();
?>
Comments
I just wanted to drop a line and thank you for you PHP pagination script. I’ve been using one for a while now that does not limit the amount of pages shown in the nav at one time, so I’ve had to limit my queries to 20 pages or so.
I’ve searched and searched for one that does what yours does and they’ve all been extremely complicated. Yours is simple to use, understand and modify to fit my needs if necessary.
I’m not a PHP newbie, but that particular solution has alluded me for some time.
Thanks again,
Shawn
Very nice pagination class!
This is bar far the best pagination script i have found. Most others require you to do the coding within the query, but because this uses an external file, it saves the amount of php coding experience you need. World class and thank you for all your time in creation. A+++++
It works great! Make sure when passing the sql statement, you don’t have a semicolon (;) at the end! I made that mistake and it took me a while time to figure it out.
well what can i say pal, it does the trick basically.
fank you mate and keep posting scripts like that
thanks alot, this is an easy to implement script, and with a little knowledge of php it can be quickly customized and integrated!