Pagination - Site Navigation for Displaying Large Data

Nov 4, 2008 | Tags: PHP | del.icio.us del.icio.us | digg Digg

This is a simple function to create pagination links; what would you need when you split large data into several pages. The function is very simple and easy to customize. It takes 4 arguments and you called it like this:

Listing 1: Usage is simple

  1. <div id="pagination">
  2.   <?php  
  3.     clean_pagination($total_rows,  
  4.                      $entries_per_page,  
  5.                      $current_page,  
  6.                      $link_to);  
  7.   ?>
  8. </div>

It will produce clean HTML in several DIVs like this:

Listing 2: HTML result

  1. <div id="pagination">
  2.         <div><a href="products.php?cat=dvd&amp;page=1">Prev</a></div>
  3.         <div><a href="products.php?cat=dvd&amp;page=1">1</a></div>
  4.         <div class="current-page">2</div>
  5.         <div><a href="products.php?cat=dvd&amp;page=3">3</a></div>
  6.         <div><a href="products.php?cat=dvd&amp;page=4">4</a></div>
  7.         <div><a href="products.php?cat=dvd&amp;page=3">Next</a></div>
  8. </div>

So you can control its appearance by using CSS in any way you like.

The Downloads

2 Comments

mahmood namvar on Oct 4, 2009:

thats very good.
thaaaaaaaaaaaaaaaaanks

shiv on Mar 11, 2010:

very helpful for us

Leave a comment

Name (required)
Email (will not be published) (required)
Website

Characters left = 1000