Posts tagged: Pagination Class

Paging Class using PHP and MySQL

Based on my last post on paging using PHP and MySQL, I have coded this class. It is very easy to implement and it will save your time. Here is a code snippet to show how simple to use it.

//include the class file
//making connection to the database
mysql_connect('localhost', 'root', '');
//prepare SQL
$sql = 'SELECT * FROM books';
//create an object of Pager passing the SQL
$pager = new Pager($sql);
//set the url. this is the current page
$pager->url = 'index.php';
//set number of rows. by default it is 10
$pager->rowPerPage = 5;
//build the pager
//get paged data
$rows = $pager->getPagedData();

Click the download link given below for a copy of the class. It also includes an working example.