Dream House

Courage to do something…

Paging Class using PHP and MySQL

Posted by Mohammad Sajjad Hossain on April 24th, 2008

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
include('Pager.php');
 
//making connection to the database
mysql_connect('localhost', 'root', '');
mysql_select_db('test');
 
//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
$pager->build();
 
//get paged data
$rows = $pager->getPagedData();

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

Download

Share/Save/Bookmark

3 Responses to “Paging Class using PHP and MySQL”

  1. Paging using PHP and MySQL | Dream House Says:

    [...] I have coded a class for paging, you may find it here. [...]

  2. Fahmi Says:

    Thanks for nice work Sajjad Bhai….
    I will try to implement it in my current project…

  3. Arafat Rahman Says:

    Everyday we need pagination.
    Hope this paging class may make our life easy.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">