Categories

Syndicate

HostGator.com

PHP Pagination Script

Listed under

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

Main Features

Usage Instructions

Step One

The first step is to include the ps_pagination.php file in your script.

Step Two

Create a ps_pagination object. The ps_pagination class constructor expects four parameters:

Step Three

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.

Step Four

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();
?>

Functions Overview

  1. renderFirst – This function displays the link to the first page
  2. renderLast – This function displays the link to the last page
  3. renderNext – This function displays link to next page
  4. renderPrevious – This function displays link to previous page
  5. renderNav – Displays the page links
  6. renderFullNav – This function displays all the pagination links in one go.

Comments

Shawn Jun 20, 2007

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

Raymond Oct 15, 2007

Very nice pagination class!

Michael Thomson Nov 24, 2007

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+++++

Joel Feb 18, 2008

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.

jack khan Mar 11, 2008

well what can i say pal, it does the trick basically.

fank you mate and keep posting scripts like that

dustin Mar 12, 2008

thanks alot, this is an easy to implement script, and with a little knowledge of php it can be quickly customized and integrated!

Post your comment
All comments are manually verified. So don't waste your time posting spam.

  Textile Help

Related Articles

Digg this article Bookmark on Delicious Add to your Technorati Favorites StumbleUpon Add to BlinkList Simpify This

More PHP Articles

Turnkey Templates