How to create Pagination with PHP and MySql – onlinecode

How to create Pagination with PHP and MySql – onlinecode

In this post we will give you information about How to create Pagination with PHP and MySql – onlinecode. Hear we will give you detail about How to create Pagination with PHP and MySql – onlinecodeAnd how to use it also give you demo for it if it is necessary.

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 >
			    <li >
				  <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 page"]==$i){ echo 'active';  } ?>"><a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php echo $i;?>"><?php echo $i;?></a>
                             </li>
				<?php
				}?>
					
			      <li >
				  <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>

Please follow and like us:

Hope this code and post will helped you for implement How to create Pagination with PHP and MySql – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  3  =  6

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US