How to Add Pagination in Php for Example
<html>
<head>
<title>admin dashboard</title>
</head>
<body>
<?php
include("config.php");
$results_per_page = 10;
$query = "select *from tb_user";
$result = mysqli_query($conn, $query);
$number_of_result = mysqli_num_rows($result);
$number_of_page = ceil ($number_of_result / $results_per_page);
if (!isset ($_GET['page']) ) {
$page = 1;
} else {
$page = $_GET['page'];
}
$page_first_result = ($page-1) * $results_per_page;
$query1 = "SELECT * FROM tb_user LIMIT " . $page_first_result . ',' . $results_per_page;
$result1 = mysqli_query($conn, $query1);
?>
<h1><center>Welcome to the Admin Dashboard</center> </h1>
<center>
<b><a href="login.php">back to login</a></b>
<b><a href="registration.php">new registration</a></b></center><br>
<center><table border="4" cellspacing="7" width="55%"></center>
<tr>
<th width="5%">Sr.no</th>
<th width="10%">Name</th>
<th width="10%">Username</th>
<th width="20%">Email</th>
<!-- <th width="10%">Password</th> -->
<th width="10%">Operations</th>
</tr>
<?php
$i = 1;
while($result = mysqli_fetch_assoc($result1))
{
echo "<tr>
<td>".$i."</td>
<td>".$result['name']."</td>
<td>".$result['username']."</td>
<td>".$result['email']."</td>
<td><a href='update_design.php?id=$result[id]'>
<input type='submit' value='Update' class='update'></a>
<a href='delete.php?id=$result[id]'>
<input type='submit' value='Delete' class='delete' onclick = 'return checkdelete()'>
</a></td>
</tr>
";
$i++;
}
?>
</table>
</a>
<?php
for($page = 1; $page<= $number_of_page; $page++) {
echo '<a href = "display.php?page=' . $page . '">' . $page . ' </a>';
}
?>
<script>
function checkdelete()
{
return confirm('Are you sure you want to delete this record ?');
}
</script>
</body>
</html>
0 Comments