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.

10 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
  4. This site is help full for every person and easily get money through bitcoin atm card .please visit this site for bitcoin atm card ranking.you can change any money into another currency in any where in the world.

    ReplyDelete
  5. I am really happy to say it’s an interesting post to read . I learn new information from your article , you are doing a great job . Keep it up.
    Php Training Courses in mumbai

    ReplyDelete
  6. There is no better idea of keeping your mobile loaded with balance all the time. If you are also looking for any useful way to utilize your top up phone with bitcoin then hurry up and avail our service as much as can. There is no limit of it. Make your mobile life happier with balance recharge through NETELL.NET. COME SOON .THANK YOU .

    ReplyDelete
  7. Want to get ranked your business on the top? Contact Shahni Digital Media, one of the fastest growing Digital Marketing Company in India. We provide web development solution, orm, ppc, smm, sem etc.
    Digital Marketing Company Bhopal
    Website Designing Company Bhopal
    SEO Company in Bhopal
    ORM Company India

    ReplyDelete
  8. Thanks for sharing the valuable information with us.These are really great and useful in all aspects,appreciated!
    PHP-MySQL Interview Questions
    Top 10 PHP Interview Questions
    PHP Functions asked in Interview

    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