pagination in php all types with free source code with example
index.php
Copy or past and run won web page
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="#">Pagination</a>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
<?php
$con = mysqli_connect("localhost","root","","tests");
$limit = 10;
$start_page = 0;
if(isset($_GET['page'])){
$page = $_GET['page'];
if($page=="" || $page=="1" || $page=="0"){
$start_page = 0;
}else{
$start_page = ($page*$limit)-$limit;
}
}
$query_run = mysqli_query($con,"SELECT * FROM `users` limit $start_page, $limit");
$count = mysqli_num_rows($query_run);
if($query_run){
?>
<div class="container">
<h2>PHP paginations </h2>
<table class="table">
<thead>
<tr>
<th>Sn.</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Mobile</th>
</tr>
</thead>
<tbody>
<?php
//while loop to get all data from database
while($row = mysqli_fetch_array($query_run)){
?>
<tr>
<td><?php echo $id = $row["id"];?></td>
<td><?php echo $id = $row["fn"];?></td>
<td><?php echo $id = $row["ln"];?></td>
<td><?php echo $id = $row[3];?></td>
<td><?php echo $id = $row[4];?></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
<div class="container">
<ul class="pagination">
<?php
$query_run_page = mysqli_query($con,"SELECT * FROM `users`");
$count_page = mysqli_num_rows($query_run_page);
$per_page = $limit;
$cell = ceil($count_page/$per_page);
?>
<?php
if(isset($_REQUEST['page'])){
if($_REQUEST['page'] > 1){
$Previous_page = $_REQUEST['page']-1;
?>
<li class="page-item"><a class="page-link" href="index.php?page=<?php echo $Previous_page; ?>">Previous</a></li>
<?php
}
}
?>
<?php
for($i=1; $i<=$cell; $i++){
if(isset($_REQUEST['page'])){
if($i==$_REQUEST['page']){
?>
<li class="page-item active" style="cursor: no-drop;"><a class="page-link active" style="cursor: no-drop;" href="#"><?php echo $i; ?></a></li>
<?php
}else{
?>
<li class="page-item"><a class="page-link" href="index.php?page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
<?php
}
}else{
?>
<li class="page-item"><a class="page-link" href="index.php?page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
<?php
}
}
?>
<?php
if(isset($_REQUEST['page'])){
$next_page = $_REQUEST['page']+1;
$lp = $_REQUEST['page'];
$lp = $lp-1;
$p = $lp*$limit;
$checkp = $p + $limit;
if($count_page < $checkp){
}else{
?>
<li class="page-item"><a class="page-link" href="index.php?page=<?php echo $next_page; ?>">Next</a>
<?php
}
}
?>
<!--<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>-->
</ul>
</div>
<?php }?>
</body>
</html>
Dere user if have any problem then u can contect me via a comment if u have any doubt in thes script or in my website any script
thnks...
thnks...
0 Comments