How To Create Pagination In PHP Using PDO

In this article, we are going to learn on How To Create Pagination In PHP Using PDO. This work is very simple, using PHP in PDO without the use of jQuery or Ajax and it is PHP use only. You can use this to your work or projects that have a lot of data to display and to minimize the space of your one page. Enjoy Coding.

Creating our Table

We are going to make our database. To create a database:
  1. Open the PHPMyAdmin.
  2. Create a database and name it as "pagination_demo".
  3. After creating a database name, then we are going to create our table. And name it as "tbl_tutorials".
  4. Kindly copy the code below.
  1. --
  2. -- Table structure for table `tbl_tutorials`
  3. --
  4.  
  5. CREATE TABLE `tbl_tutorials` (
  6. `tuts_id` INT(11) NOT NULL,
  7. `tuts_title` VARCHAR(100) NOT NULL,
  8. `tuts_link` VARCHAR(150) NOT NULL
  9. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  10.  
  11. --
  12. -- Dumping data for table `tbl_tutorials`
  13. --
  14.  
  15. INSERT INTO `tbl_tutorials` (`tuts_id`, `tuts_title`, `tuts_link`) VALUES
  16. (1, 'How To Flip The Image', 'http://www.sourcecodester.com/tutorials/htmlcss/10263/how-flip-image.html'),
  17. (2, 'How To Count Number Of Vowels And Consonants', 'http://www.sourcecodester.com/tutorials/javascript/10264/how-count-number-vowels-and-consonants.html'),
  18. (3, 'How To Create Converter For Decimal To Roman Numeral', 'http://www.sourcecodester.com/tutorials/javascript/10265/how-create-converter-decimal-roman-numeral.html'),
  19. (4, 'Online Public Access Catalog For Library System', 'http://www.sourcecodester.com/tutorials/php/10266/online-public-access-catalog-library-system.html'),
  20. (5, 'How To Create Registration Page In PHP/MySQL', 'http://www.sourcecodester.com/tutorials/php/10268/how-create-registration-page-phpmysql.html'),
  21. (6, 'How To Create Login Page In PHP/MySQL', 'http://www.sourcecodester.com/tutorials/php/10269/how-create-login-page-phpmysql.html'),
  22. (7, 'How To Create Import CSV/Excel File To MySQL Database Using PHP', 'http://www.sourcecodester.com/tutorials/php/10270/how-create-import-csvexcel-file-mysql-database-using-php.html'),
  23. (8, 'Attendance Monitoring System Using PHP', 'http://www.sourcecodester.com/tutorials/php/10280/attendance-monitoring-system-using-php.html'),
  24. (9, 'How To Create Registration Form In PHP/MySQL Using PDO Query', 'http://www.sourcecodester.com/tutorials/php/10292/how-create-registration-form-phpmysql-using-pdo-query.html'),
  25. (10, 'Search Two Dates In Data Table Using PHP', 'http://www.sourcecodester.com/tutorials/php/10258/search-two-dates-data-table-using-php.html');
Data in the Database All Data

Sample Source Code

Where you can set the amount of data per page to display.
  1. <table align="center" border="1" width="100%" height="100%" id="data">
  2. <tr style="text-align:center; color:blue; font-size:20px;">
  3. <td>No.</td>
  4. <td>Title</td>
  5. <td>Action</td>
  6. </tr>
  7. <?php
  8. $query = "SELECT * FROM tbl_tutorials";
  9. $data_per_Page=5;
  10. $query_1 = $pagination->paging($query,$data_per_Page);
  11. $pagination->dataview($query_1);
  12. $pagination->paginglink($query,$data_per_Page);
  13. ?>
  14. </table>

Output:

This is the first page. First PageThis is the second page. Second Page So, this is it, or you can download the full source code below by clicking the "Download Code" button below. Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment