Simple PHP Pagination Example Tutorial

Simple PHP Pagination Example Tutorial

Today, We want to share with you Simple PHP Pagination Example Tutorial.In this post we will show you Creating Paging using PHP and MySQL, hear for dynamic pagination in php with mysql example we will give you demo and example for implement.In this post, we will learn about pagination code in php with next and previous with an example.

Simple PHP Pagination Example Tutorial

There are the Following The simple About Simple PHP Pagination Example Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Simple pagination for array collections, so the some Simple PHP Pagination script for this example is following below.

Read Also:  call to undefined function mysql_pconnect()

PHP array pagination Example

<!DOCTYPE html> 
    <title>Simple PHP Pagination script</title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet"
        display: inline-block; 
        float: right; 
        margin: 20px 0px; 
    input, button{ 
        height: 34px; 
    require_once "db_connection.php"; 

    $limit = 10; 
    if (isset($_GET["page"])) { 
    $page_num = $_GET["page"]; 
    else { 

    $start_from = ($page_num-1) * $limit; 

    $sql = "SELECT * FROM products LIMIT $start_from, $limit"; 
    $products_res = mysql_query ($sql); 

<div class="container"> 
    <h1>Dynamic pagination in php with mysql example</h1> 
    <p>This page is just for Simple PHP Examples of Basic Pagination using PHP.</p> 
    <table class="table table-striped table-condensed table-bordered"> 
        <th width="10%">Rank</th> 
        while ($get_row = mysql_fetch_array($products_res, MYSQL_ASSOC)) { 
        <td><?php echo $get_row["rank"]; ?></td> 
        <td><?php echo $get_row["name"]; ?></td> 
        <td><?php echo $get_row["college"]; ?></td> 
        <td><?php echo $get_row["score"]; ?></td>                                        
    <ul class="pagination"> 
        $sql = "SELECT COUNT(*) FROM products"; 
        $products_res = mysql_query($sql); 
        $get_row = mysql_fetch_get_row($products_res); 
        $total_records = $get_row[0]; 
        $product_total_pages = ceil($total_records / $limit); 
        $k = (($page_num+4>$product_total_pages)?$product_total_pages-4:(($page_num-4<1)?5:$page_num));      
        $pagLink = ""; 
            echo "<li><a href='index.php?page=1'> << </a></li>"; 
            echo "<li><a href='index.php?page=".($page_num-1)."'> < </a></li>"; 
        for ($i=-4; $i<=4; $i++) { 
            $pagLink .= "<li class='active'><a href='index.php?page=".($k+$i)."'>".($k+$i)."</a></li>"; 
            $pagLink .= "<li><a href='index.php?page=".($k+$i)."'>".($k+$i)."</a></li>"; 
        echo $pagLink; 
            echo "<li><a href='index.php?page=".($page_num+1)."'> > </a></li>"; 
            echo "<li><a href='index.php?page=".$product_total_pages."'> >> </a></li>"; 
    <div class="inline"> 
    <input id="page_num" type="number" min="1" max="<?php echo $product_total_pages?>"
    placeholder="<?php echo $page_num."/".$product_total_pages; ?>" required> 
    <button onclick="next_page_redirect();">Go</button> 
    function next_page_redirect() 
        var page_num = document.getElementById("page_num").value; 
        page_num = ((page_num><?php echo $product_total_pages; ?>)?<?php echo $product_total_pages; ?>:((page_num<1)?1:page_num)); 
        window.location.href = 'index.php?page='+page_num; 

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Bootstrap Toggle switch with ajax update to mysql in PHP


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Simple PHP Pagination Example Tutorial.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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