Monday, 21 May 2018

php pagination script with mysqli

23:55

<?php

    $con=mysqli_connect("localhost","root","","payroll");
 
    $per_page = 2; //per page record



 
$pages_query = mysqli_query($con, 'SELECT COUNT(id) FROM employee');

$row = mysqli_fetch_array($pages_query);

$pages = ceil($row[0] / $per_page);


 

//echo $pages;
 
    $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; //page number throung url

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

  $sql="SELECT *  FROM employee LIMIT $start, $per_page";
 
  $query = mysqli_query($con,$sql);

while($row=mysqli_fetch_array($query))
{

echo "id is" .$row['id'];
echo $row['name'];
echo $row['phone'];
echo $row['salary'];

echo '<br>';
}

$prev = $page - 1;
    $next = $page + 1;
 
    if(!($page<=1))
{
        echo "<a href='pag.php?page=$prev'>Prev</a> ";
    }

    if($pages>=1 && $page<=$pages){
 
        for($x=1;$x<=$pages;$x++){
            echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> ';
     
        }
 
    }
 
    if(!($page>=$pages))
{
        echo "<a href='pag.php?page=$next'>Next</a>";
    }
 
 
?>

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

3 comments:

  1. Such useful information provided by you. These details are both very beneficial for both newbies and experienced ones. Thank you for the post.
    Web Design Company | Web development Lucknow

    ReplyDelete
  2. Thanks For Sharing. It IS very helpful For Everyone ....
    If You Are Looking Best PHP training in chandigarh click here

    ReplyDelete
  3. Great and helpful post and Thanks for sharing this article. we are leading the Best PHP training institute and web development and designing training in Jodhpur .

    ReplyDelete

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top