Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
PHP Pagination Function Example
Sponsered Links
Categories
Sponsered Links

PHP Pagination Function Example

This is the pagination example of php. In this example we create two function for limit of record.

<?php
    /*
    function getPagingQuery($sql, $itemPerPage = 10) {
        if (isset($_GET['page']) && (int) $_GET['page'] > 0) {
            $page = (int) $_GET['page'];
        } else {
            $page = 1;
        }
        $offset = ($page - 1) * $itemPerPage;   
        return $sql . " LIMIT $offset, $itemPerPage";
    }
    /*
        Create the paging links
    */
    /*
    function getPagingNav($sql, $pageNum, $rowsPerPage, $queryString = ''){
        $result  = mysql_query($sql) or die('Error, query failed. ' . mysql_error());
        $row     = mysql_fetch_array($result, MYSQL_ASSOC);
        $numrows = $row['numrows'];
       
        // how many pages we have when using paging?
        $maxPage = ceil($numrows/$rowsPerPage);
       
        $self = $_SERVER['PHP_SELF'];
       
        // creating 'previous' and 'next' link
        // plus 'first page' and 'last page' link
       
        // print 'previous' link only if we're not
        // on page one
        if ($pageNum > 1) {
            $page = $pageNum - 1;
            $prev = " <a href=\"$self?page=$page{$queryString}\">[Prev]</a> ";
       
            $first = " <a href=\"$self?page=1{$queryString}\">[First Page]</a> ";
        } else {
            $prev  = ' [Prev] ';       // we're on page one, don't enable 'previous' link
            $first = ' [First Page] '; // nor 'first page' link
        }
       
        // print 'next' link only if we're not
        // on the last page
        if ($pageNum < $maxPage) {
            $page = $pageNum + 1;
            $next = " <a href=\"$self?page=$page{$queryString}\">[Next]</a> ";
       
            $last = " <a href=\"$self?page=$maxPage{$queryString}{$queryString}\">[Last Page]</a> ";
        } else {
            $next = ' [Next] ';      // we're on the last page, don't enable 'next' link
            $last = ' [Last Page] '; // nor 'last page' link
        }
       
        // return the page navigation link
        return $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
    }
    */
?>

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved