Skip to content

Instantly share code, notes, and snippets.

@Mauryashubham
Created July 8, 2019 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mauryashubham/e24b242b5c030a14d5cc64cc6903c9bb to your computer and use it in GitHub Desktop.
Save Mauryashubham/e24b242b5c030a14d5cc64cc6903c9bb to your computer and use it in GitHub Desktop.
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.html 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>
Comment Below, If any problem occurs.
STAY CONNECTED FOR MORE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment