In this tutorial, I will inform you How to create Pagination with PHP and MySql.

Pagination means document content dividing into multiple pages. whenever we have one long page at that time we dividing into multiple pages.

if you want to create pagination using MySQL at that time use limit clause, it takes two arguments first is "offset" and the second is the "end". end means a number of records returned from the database.

I have share post next and previous button with code in this tutorial and I hope it will be helping you. below example in 3 records displayed per page.

<html>
<head>
     <title>How to create Pagination with PHP and MySql?</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script
</head>
<body>

<table border="1" align="center">
	<tr>
	     <td colspan="7" align="right"><a href="add.php">Add</a></td>
	</tr>
	<tr>
	     <td>First Name</td>
	     <td>Last Name</td>
	     <td>Address</td>
	     <td>Email</td>
	     <td>Mobile</td>
	     <td>Action</td>
	</tr>
	<?php
	include('connection.php');
	$total=3;
	if (isset($_GET["page"]))
	{
		$page  = $_GET["page"];
	}
	else
	{
		$page=1;
	}
	$start = ($page-1) * $total;
	$slt="select * from register LIMIT $start,$total";
	$rec=mysqli_query($conn,$slt);
	while($row=mysqli_fetch_array($rec))
	{
	?>
		<tr>
		   <td><?php echo $row['first_name']; ?></td>
		   <td><?php echo $row['last_name']; ?></td>
		   <td><?php echo $row['email']; ?></td>
		   <td><?php echo $row['address']; ?></td>
		   <td><?php echo $row['mobile']; ?></td>
		   <td><a href="update.php?edit_id=<?php echo $row['id'];?>">Edit</a>&nbsp;&nbsp;<a href="delete.php?delete_id=<?php echo $row['id'];?>">Delete</a> </td>
		</tr>
	<?php
	}
	?>
	<tr>
		<td colspan="7">
			<ul class="pagination">
			    <li class="<?php if($page==1){ echo 'disabled';} ?>">
				  <a href="<?php if($page==1){ echo '#';} else {?><?php echo $_SERVER['PHP_SELF']?>?page=<?php echo $page-1; }?>" aria-label="Previous">
					<span aria-hidden="true">Previous</span>
				  </a>
			     </li>
			      <?php
				$slt="select * from register";
				$rec=mysqli_query($conn,$slt);
				$total1=mysqli_num_rows($rec);
				$total_pages = ceil($total1 / $total);
				for($i=1;$i<=$total_pages;$i++)
				{?>
			     <li class="<?php if($_GET["page"]==$i){ echo 'active';  } ?>"><a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php echo $i;?>"><?php echo $i;?></a>
                             </li>
				<?php
				}?>
					
			      <li class="<?php if($page==$total_pages){ echo 'disabled'; } ?>">
				  <a href="<?php if($page==$total_pages){ echo '#';} else {?><?php echo $_SERVER['PHP_SELF']?>?page=<?php echo $page+1; }?>" aria-label="Next">
					<span aria-hidden="true">Next</span>
				  </a>
			      </li>
			</ul>
		</td>
	</tr>
</table>
</body>
</html>