PHP-Pagination Example

The below example shows that how to retrieve records from MySQL Database using PHP Pagination technique.

In the below example  included image along with text information. For image and text storing and retrieving you can click here and refer the same.

First of all create a php file called “pagination2.php” with following code in it.

<title>Members Information Pagewise</title>
<body bgcolor=khaki>
<h1 align=center>Members Information Pagewise</h1>
<hr color=green>
$con = mysqli_connect('localhost','root','','demo');
//per page records
if (isset($_GET["page"])) {
$page = $_GET["page"];

else {

$start_from = ($page-1) * $per_page;

//Selecting the data from table with LIMIT
$query = "SELECT * FROM members2 LIMIT $start_from, 

$result = mysqli_query ($con, $query);

<table align="center" border="1" cellpadding="4" 

<tr bgcolor=white><th>Members 


while ($row = mysqli_fetch_assoc($result)) {
<tr align="center" bgcolor=skyblue>
<td><?php echo $row['memname']; ?></td>
<td><?php echo $row['qual']; ?></td>
<td> <?php echo "<img src='uploaded/".$row['photo']."' 

height=100 width=100 />" ?> 




//select all records from members2 table in this example
$query = "select * from members2";
$result = mysqli_query($con, $query);

// Count the total records present in the table
$total_records = mysqli_num_rows($result);

//Function ceil to divide the total records on per page
$total_pages = ceil($total_records / $per_page);

//Lets go to first page , here you can use icons or text to 

give hyperlinks
echo "<center><a href='pagination2.php?page=1'>".'<img 


for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='pagination2.php?page=".$i."'>".$i."</a> ";
// Lets move to last page
echo "<a 


<hr color=green>

The output of the above program would produce following image.