PHP Pagination demo – Pagination in PHP with example script

Are you searching for easy PHP pagination demo for a really beginner level then i believe this PHP pagination example is very abundant helpful for you. PHP pagination demo may be a technique to divide content into many pages. Here we are able to assign every page a separate URL.

Dynamic pagination in php with mysql example

pagination code in php with next and previous demo
pagination code in php with next and previous demo

By Clicking that uniform resource locator or folio, user will read this Page. for each page we have a tendency to assign a progressive page number. you’ll be able to free transfer easy PHP Pagination demo script or PHP number demo code from here. Before that bear once with pagination in php demo link.
Also Read: Simple PHP Pagination Example Tutorial
Here I used php script with mysqli. we have a tendency to Hope this PHP pagination demo example or php pagination tutorial mistreatment PHP MYSQL can assist you to induce the fundamental information concerning the pagination as a beginner in php.

Take a quick investigate this live demo to know the flow of the easy pagination using php and mysql.

Creating New Database table

--
-- Database: `cricketers`
--

-- --------------------------------------------------------

--
-- Table structure for table `tbl_cricketer`
--

CREATE TABLE IF NOT EXISTS `tbl_cricketer` (
  `cricketer_id` int(11) NOT NULL AUTO_INCREMENT,
  `cricketer_name` varchar(250) NOT NULL,
  `cricketer_phone` varchar(20) NOT NULL,
  PRIMARY KEY (`cricketer_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=51 ;

--
-- Dumping data for table `tbl_cricketer`
--

INSERT INTO `tbl_cricketer` (`cricketer_id`, `cricketer_name`, `cricketer_phone`) VALUES
(1, 'Sachin Tendulkar', '412-735-0884'),
(2, 'Don Bradman', '320-552-9961'),
(3, 'Garfield Sobers', '201-324-8264'),
(4, 'Sir Viv Richards', '478-388-4715'),
(5, 'Imran Khan', '479-966-6788'),
(6, 'Ian Botham', '701-685-8912'),
(7, 'Shane Warne', '607-829-8758'),
(8, 'Muttiah Muralitharan', '803-789-0429'),
(9, 'Brian Lara', '214-585-0737'),
(10, 'Virat Kohli', '630-571-4107'),
(11, 'Jacques Kallis', '904-459-3747'),
(12, 'MS Dhoni', '404-380-9481'),
(13, 'Wasim Akram', '323-350-4483'),
(14, 'Kumar Sangakkara', '337-889-2683'),
(15, 'Kapil Dev', '216-394-6894'),
(16, 'Mahela Jayawardene', '503-284-8652'),
(17, 'Adam Gilchrist', '989-304-7188'),
(18, 'Chris Gayle', '540-232-0351'),
(26, 'Virender Sehwag', '718-262-7466'),
(20, 'Allan Donald', '407-492-5727'),
(21, 'Glenn McGrath', '903-863-5810'),
(88, 'Sunil Gavaskar', '482-421-6933'),
(23, 'Rahul Dravid', '920-348-4884'),
(24, 'Ajinkya Rahane', '615-425-9930'),
(25, 'Jacques Kallis', '708-887-2613'),
(26, 'P Duminy', '909-386-7998'),
(27, 'Suresh Raina', '630-643-8763'),
(28, 'Graeme Smith', '513-807-9884'),
(29, 'Gautam Gambhir', '847-385-1621'),
(30, 'Eoin Morgan', '561-641-4509'),
(31, 'Nicholas Pooran', '508-269-9346'),
(32, 'Jonny Bairstow', '347-537-8052'),
(33, 'Shreyas Iyer', '510-702-7415'),
(34, 'Suryakumar Yadav', '252-226-4076'),
(35, 'Shikhar Dhawan', '810-334-9674'),
(36, 'Quinton de Kock', '865-259-6772'),
(37, 'David Warner', '443-217-1859'),
(38, 'Babar Azam', '716-252-9230'),
(39, 'Virat Kohli', '402-840-0541'),
(40, 'Mayank Agarwal', '360-610-7730'),
(41, 'Faf du Plessis', '205-861-3306'),
(42, 'KL Rahul', '914-683-4994'),
(43, 'AB De Villiers', '310-335-1336'),
(44, 'Sourav Ganguly', '626-513-8306'),
(45, 'Yuvraj Singh', '754-884-7023'),
(46, 'Anil Kumble', '806-823-5344'),
(47, 'Mike Hussey', '201-917-2804'),
(48, 'Matthew Hayden', '206-592-4665'),
(49, 'Jack Hobbs', '488-365-0324'),
(50, 'Lasith Malinga', '815-288-5435');


Also Read: pagination code in php with next and previous demo

Read Also:  Email validation in JavaScript on button click - How to Perform Email Validation in JavaScript?

Pagination using PHP MySql

cricketers_list.php

<?php
$connect = mysqli_connect("localhost", "root", "", "cricketers");
$record_per_page = 5;
$page = '';
if(isset($_GET["page"]))
{
 $page = $_GET["page"];
}
else
{
 $page = 1;
}

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

$query = "SELECT * FROM tbl_cricketer order by cricketer_id DESC LIMIT $start_from, $record_per_page";
$result = mysqli_query($connect, $query);

?>

<!DOCTYPE html>
<html>
 <head>
  <title>PHP Pagination with Next Previous First Last page Link - www.pakainfo.com</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  <style>
  a {
   padding:8px 16px;
   border:1px solid #ccc;
   color:#333;
   font-weight:bold;
  }
  </style>
 </head>
 <body>
  <br /><br />
  <div class="container">
   <h3 align="center">PHP Pagination with Next Previous First Last page Link - - www.pakainfo.com</h3><br />
   <div class="table-responsive">
    <table class="table table-bordered">
     <tr>
      <td>Name</td>
      <td>Phone</td>
     </tr>
     <?php
     while($row = mysqli_fetch_array($result))
     {
     ?>
     <tr>
      <td><?php echo $row["cricketer_name"]; ?></td>
      <td><?php echo $row["cricketer_phone"]; ?></td>
     </tr>
     <?php
     }
     ?>
    </table>
    <div align="center">
    <br />
    <?php
    $page_query = "SELECT * FROM tbl_cricketer ORDER BY cricketer_id DESC";
    $page_result = mysqli_query($connect, $page_query);
    $total_records = mysqli_num_rows($page_result);
    $total_pages = ceil($total_records/$record_per_page);
    $start_loop = $page;
    $difference = $total_pages - $page;
    if($difference <= 5)
    {
     $start_loop = $total_pages - 5;
    }
    $end_loop = $start_loop + 4;
    if($page > 1)
    {
     echo "<a href='cricketers_list.php?page=1'>First</a>";
     echo "<a href='cricketers_list.php?page=".($page - 1)."'><<</a>";
    }
    for($i=$start_loop; $i<=$end_loop; $i++)
    {     
     echo "<a href='cricketers_list.php?page=".$i."'>".$i."</a>";
    }
    if($page <= $end_loop)
    {
     echo "<a href='cricketers_list.php?page=".($page + 1)."'>>></a>";
     echo "<a href='cricketers_list.php?page=".$total_pages."'>Last</a>";
    }
    
    
    ?>
    </div>
    <br /><br />
   </div>
  </div>
 </body>
</html>

DOWNLOAD CODE ::

Read Also:  having clause sql Example

Also Read:

don’t have any text to check? don’t have any text to check? Click “Select Samples”.Thanks for looking this post. you’ll strive yourself. we are going to share some helpful script in PHP still as some tips and tricks in PHP programming.

Viewers will subscribe our story to induce all the updates regarding net programming.

Also Read: Advanced Pagination with PHP, MySQL and jQuery Demo

If you’re thinking that this post is beneficial for beginner then please share it.