/Bootstrap Simple Pagination
bootstrap simple pagination

Bootstrap Simple Pagination

How to make bootstrap simple pagination using PHP
/**
@author : Shubham Maurya,
Email id : maurya.shubham5@gmail.com
**/

Hi all , Welcome to shubhammaurya.com , Today we are going to discuss ,
How to make Bootstrap Simple Pagination using PHP

In this,we are going to use Bootstrap as front-end framework.

 LETS START

Bootstrap Simple Pagination using PHP

So, To start first make a file in notepad and save it as index.php and paste the below code.

<?php

// database using PDO 
include("dbconfig.php");

// Pagination Starts
$showRecordPerPage = 3;
if(isset($_GET['page']) &amp;&amp; !empty($_GET['page'])){
$currentPage = $_GET['page'];
}else{
$currentPage = 1;
}
$startFrom = ($currentPage * $showRecordPerPage) - $showRecordPerPage;
$totalEmpSQL = "SELECT * FROM employee";
$allEmpResult = mysqli_query($conn, $totalEmpSQL);
$totalEmployee = mysqli_num_rows($allEmpResult);
$lastPage = ceil($totalEmployee/$showRecordPerPage);
$firstPage = 1;
$nextPage = $currentPage + 1;
$previousPage = $currentPage - 1;

// Fetch data
$stmt=$dbcon->prepare("SELECT * from employee LIMIT $startFrom, $showRecordPerPage");
$stmt->execute(array(':status'=>1));
$data_check=$stmt->fetchAll(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Simple Pagination</title>
</head>
<body>

          <!-- data -->
          <?php if($data_check){ foreach($data_check as $ch){?>
          <label>Display Your Data Here</label>
          <?php ?>

          <!-- Pagination -->
          <div class="col-md-12">
     <nav aria-label="Page navigation">
<ul class="pagination">
<?php if($currentPage != $firstPage) { ?>
<li class="page-item">
<a class="page-link" href="?page=<?php echo $firstPage ?>" tabindex="-1" aria-label="Previous">
<span aria-hidden="true">First</span>
</a>
</li>
<?php } ?>
<?php if($currentPage >= 2) { ?>
<li class="page-item"><a class="page-link" href="?page=<?php echo $previousPage ?>"><?php echo $previousPage ?></a></li>
<?php } ?>
<li class="page-item active"><a class="page-link" href="?page=<?php echo $currentPage ?>"><?php echo $currentPage ?></a></li>
<?php if($currentPage != $lastPage) { ?>
<li class="page-item"><a class="page-link" href="?page=<?php echo $nextPage ?>"><?php echo $nextPage ?></a></li>
<li class="page-item">
<a class="page-link" href="?page=<?php echo $lastPage ?>" aria-label="Next">
<span aria-hidden="true">Last</span>
</a>
</li>
<?php } ?>
</ul>
</nav>
  </div>
</body>
</html>

       

Download the project from Github : Download

Comment Below, If any problem occurs.

STAY CONNECTED FOR MORE

Get More Bootstrap Code Here : Go Here

Hi , My Name is Shubham Maurya and i am currently working as a Project Manager.