PHP Page Navigation

Submitted by: 
Visitors have accessed this post 15390 times.

I created this script from PHP Pagination Class. It took me half an hour to create this little script. This script is very useful if you want page navigation in your record.


Just include the class file.


then create a new object.

$pager = new PS_Pagination($conn, $sql, 8, 10);

Complete source code:

  1. <?php
  2. //Include the PS_Pagination class
  3. include('ps_pagination.php');
  5. //Connect to mysql db
  6. $conn = mysql_connect('localhost','root','');
  7. if(!$conn) die("Failed to connect to database!");
  8. $status = mysql_select_db('countries', $conn);
  9. if(!$status) die("Failed to select database!");
  10. $sql = 'SELECT * FROM tblcountries';
  12. /*
  13. * Create a PS_Pagination object
  14. *
  15. * $conn = MySQL connection object
  16. * $sql = SQl Query to paginate
  17. * 10 = Number of rows per page
  18. * 5 = Number of links
  19. * "param1=valu1&param2=value2" = You can append your own parameters to paginations links
  20. */
  22. //Create a PS_Pagination object
  23. $pager = new PS_Pagination($conn, $sql, 8, 10);
  25. //The paginate() function returns a mysql result set for the current page
  26. $rs = $pager->paginate();
  27. ?>
  28. <h1 style="text-align:center">Page Navigation in PHP</h1>
  29. <table width="400" border="1" align="center">
  30. <tr>
  31. <td width="100" bgcolor="#CCCCCC"><p>Country ID</p></td>
  32. <td width="300" bgcolor="#CCCCCC">Country</td>
  33. </tr>
  34. <?php
  35. //Loop through the result set just as you would loop
  36. //through a normal mysql result set
  37. while($row = mysql_fetch_assoc($rs)) {
  38. ?>
  39. <tr>
  40. <td><?php echo $row['CountryID'] ?></td>
  41. <td><?php echo $row['Country'] ?></td>
  42. </tr>
  43. <?php
  44. }
  45. ?>
  46. </table>
  47. <?php
  48. //Display the navigation
  49. //echo $pager->renderFullNav();
  50. echo '<div style="text-align:center">'.$pager->renderFullNav().'</div>';
  51. ?>

Create a database called “Countries” then import the countries.sql using phpMyAdmin.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


thank you ...
its work good

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.