PHP Page Navigation

Language
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. Usage: Just include the class file. include('ps_pagination.php'); 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');
  4.        
  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';
  11.        
  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.          */
  21.          
  22.         //Create a PS_Pagination object
  23.         $pager = new PS_Pagination($conn, $sql, 8, 10);
  24.  
  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 SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

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.

Comments

Add new comment