PHP Page Navigation
Submitted by admin on Wednesday, November 7, 2012 - 12:57.
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.
Create a database called “Countries” then import the countries.sql using phpMyAdmin.
include('ps_pagination.php');
then create a new object.
$pager = new PS_Pagination($conn, $sql, 8, 10);
Complete source code:
- <?php
- //Include the PS_Pagination class
- include('ps_pagination.php');
- //Connect to mysql db
- $sql = 'SELECT * FROM tblcountries';
- /*
- * Create a PS_Pagination object
- *
- * $conn = MySQL connection object
- * $sql = SQl Query to paginate
- * 10 = Number of rows per page
- * 5 = Number of links
- * "param1=valu1¶m2=value2" = You can append your own parameters to paginations links
- */
- //Create a PS_Pagination object
- $pager = new PS_Pagination($conn, $sql, 8, 10);
- //The paginate() function returns a mysql result set for the current page
- $rs = $pager->paginate();
- ?>
- <h1 style="text-align:center">Page Navigation in PHP</h1>
- <table width="400" border="1" align="center">
- <tr>
- <td width="100" bgcolor="#CCCCCC"><p>Country ID</p></td>
- <td width="300" bgcolor="#CCCCCC">Country</td>
- </tr>
- <?php
- //Loop through the result set just as you would loop
- //through a normal mysql result set
- ?>
- <tr>
- <td><?php echo $row['CountryID'] ?></td>
- <td><?php echo $row['Country'] ?></td>
- </tr>
- <?php
- }
- ?>
- </table>
- <?php
- //Display the navigation
- //echo $pager->renderFullNav();
- echo '<div style="text-align:center">'.$pager->renderFullNav().'</div>';
- ?>
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
- Add new comment
- 463 views