How to make PHP Pagination With Example and Demo

In this example i am going to explain how to create pagination or feature using PHP and MySQLi .


$dbname = "my_db";
die('Could not Connect My Sql:' .mysql_error());
$limit = 10;  
if (isset($_GET["page"])) {
	$page  = $_GET["page"]; 
$start_from = ($page-1) * $limit;  
$result = mysqli_query($conn,"SELECT * FROM user_table ORDER BY userid ASC LIMIT $start_from, $limit");
<!DOCTYPE html>
<html lang="en">
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>
<table class="table table-bordered table-striped">  
<th>First name</th>
<th>Last name</th>
 <th>City name</th>
while ($row = mysqli_fetch_array($result)) {  
				<td><?php echo $row["userid"]; ?></td>  
				<td><?php echo $row["first_name"]; ?></td>
				<td><?php echo $row["last_name"]; ?></td>
				<td><?php echo $row["city_name"]; ?></td>
				<td><?php echo $row["email"]; ?></td>			

$result_db = mysqli_query($conn,"SELECT COUNT(id) FROM user_table"); 
$row_db = mysqli_fetch_row($result_db);  
$total_records = $row_db[0];  
$total_pages = ceil($total_records / $limit); 
/* echo  $total_pages; */
$pagLink = "<ul class='pagination'>";  
for ($i=1; $i<=$total_pages; $i++) {
              $pagLink .= "<li class='page-item'><a class='page-link' href='pagination.php?page=".$i."'>".$i."</a></li>";	
echo $pagLink . "</ul>";