PHP Simple Pagination With Bootstrap

0
81
PHP Simple Pagination With Bootstrap

Pagination is a process of split content in different pages. Pagination mostly used in digital content. In the article, I’ll show you pagination with PHP. When you have many posts or list on your website or blog then you use pagination.

It’s simple pagination for PHP beginner level developer. Later I’ll add more features with it. I’ll use Bootstrap 4, PHP 7 and MySQLi. If you complete basic PHP and MySQL from W3Schools, you will easily understand the tutorial.

So let’s start to make pagination with PHP

At first, need to create a database for it. Where from we’ll pull data for displaying in our webpage. Actually, we’ll paginate on the database content. Here is the database-

After database creation, we need to create a database connection. Let’s create db.php

Now we need to work on the main file index.php. Here I’m explaining part by part of our main code.

At first, I’ve included the database. Then I’ve defined how many contents I’ll display per page. Then defined an empty variable $page=””. This variable will contain per page data. Next, there have a condition to get variable from URL. Then have a simple calculation and ‘SELECT’ query for pulling data from the database.

Now let’s create a table and iterate a table row for displaying database content which we’ve pulled from the database with the above code.

In the above code a table created and a row iterated with ‘while()’ loop. If you know basic PHP, you should know how to it work. Later I’ve written code for the PHP pagination. Here have also another ‘SELECT’ query, but here pulled content split into different pages with the ‘for’ loop.

Here also I’ve set an ‘active’ class. If the current page number and URL page number (which we’ve received from the $_GET variable) become same, then the ‘active’ will be added.

Simply it was the pagination with PHP. Later I’ll add the total page, total item, next-previous link etc. Share the article on your social profile.

LEAVE A REPLY

Please enter your comment!
Please enter your name here