PHP Paging Program paginator program code _php Tutorial

Source: Internet
Author: User
This article to introduce to you a paginator PHP page program code, the need for friends to enter the reference.
The code is as follows Copy Code

Class Paginator {

function __construct () {

}

static function render ($page _type, array $args = Array ()) {
$html = ";
Switch ($page _type)
{
Case ' 1 ':
$html = Page_1 ($channel _code, $page _num, $cur _page, $per _group, $base _url, $n, $v);
Break
Case ' 2 ':
$html = Fpage ($row _num, $pagesize, $page, $url);
Break
Case ' 3 ':
Break

Default
$html = page ($num, $perpage, $curpage, $mpurl, $hiddenFrom = ');
}

return $html;
}



Function 1: Paging navigation based on total number of pages, current page, and page grouping and URL
function Page_1 ($channel _code, $page _num, $cur _page, $per _group, $base _url, $n, $v) {
Paging function parameter list (number of pages, current page, number of pages per page, link address)
$base _url. = Strpos ($base _url, '? ')? ' & ': '? '; If there is, add &

$page _val = "";

if ($page _num < 1) {
return $page _val; If less than 1, returns an empty
} elseif ($page _num = = 1) {
return $page _val = 1; If equals 1, returns 1
}

Group

$group _OK =! ($page _num-1)% ($per _group-1)); No remainder
Calculate how many groups there are
if ($group _ok) {
$group _num = ($page _num-1)/($per _group-1);
}else {
$group _num = Ceil (($page _num-1)/($per _group-1);
}//Determines whether the current page is the last of a group


Number of groups
$is _last_page =! ($cur _page-1)% ($per _group-1)); Calculate the number of groups currently in
if ($is _last_page) {
$cur _group = ($cur _page-1)/($per _group-1) + 1;
} else {
$cur _group = Ceil (($cur _page-1)/($per _group-1);
}

Calculates the starting page of the display, the key
$from = ($cur _group-1) * ($per _group-1) + 1;
$from = $cur _group <= 1? 1: $from;

$to = $from + $per _group;
$to = $to > $page _num? $page _num + 1: $to;

for ($a = $from; $a < $to; $a + +) {
if ($a! = $cur _page) {

Not current page
$page _val. = '
  • ' . $a. '
  • ';
    } else {
    Current page
    $page _val. = '
  • '. $a. '
  • ';
    }
    }

    Previous Next home last page
    $next = $cur _page + 1; Current Page +1
    $prev = $cur _page-1; Current Page-1

    if ($cur _page! = $page _num) {
    The current page is not the last page
    $page _val. = '' . ' Next page '. '';
    $page _val. = '' . ' >> '. ''; Last

    }
    if ($cur _page! = 1) {

    Not the first page, plus the previous content
    $page _val = '' . ' Previous page '. '' . $page _val;
    $page _val = '' . ' << '. '' . $page _val; Home

    }
    $page _val = '
        '. $page _val. '
    ';


    return $page _val;
    }




    Function 2: Based on number of records, page Lieqing, current page, URL year component page
    function Fpage ($row _num, $pagesize, $page, $url) {
    $page, current page; Total number of records $row _num; $pagesize: Number of records per page; $url record page;
    If, if there is a count, take 1 plus
    $page _count = $row _num% $pagesize? intval ($row _num/$pagesize) + 1:intval ($row _num/$pagesize);

    if ($page _count = = 1) {
    $page _string = "First page | previous page | next page | last page";
    } else {
    If more than one page
    if ($page = = 1) {
    The first page shows
    $page _string = "First page | previous page | Next Page | Last ";
    }
    if (($page > 1) and ($page < $page _count)) {
    $page _string = "First page | Prev | ($page + 1). "> Next Page | Last ";
    }
    if ($page = = $page _count) {
    $page _string = "First page | Prev | next | Last ";
    }
    }
    $page _str = $page _string. (",". $page. "/" . $page _count. "Page");
    echo "

    " . $page _str. "

    ";
    }


    /**
    * Paging function
    *
    * @param int $num: Total Records
    * @param int $perpage: Records per page
    * @param int $curpage: Current page
    * @param string $mpurl: Path URL
    * @param unknown_type $hiddenFrom
    * @return String
    */
    Function page ($num, $perpage, $curpage, $mpurl, $hiddenFrom = ') {
    $multipage = ";
    Recovery
    $mpurl. = Strpos ($mpurl, '? ')? ' & ': '? ';

    if ($num > $perpage) {
    $page = 10;
    $offset = 2;

    $pages = @ceil ($num/$perpage); Total pages

    if ($page > $pages) {
    $from = 1;
    $to = $pages;
    } else {
    If the total number of pages >10
    $from = $curpage-$offset; Current Page-2
    $to = $from + $page-1; Current Page +10-3

    if ($from < 1) {

    $to = $curpage + 1-$from;
    $from = 1;
    if ($to-$from < $page) {
    $to = $page;
    }
    } elseif ($to > $pages) {
    $from = $pages-$page + 1;
    $to = $pages;
    }
    }

    if ($hiddenFrom) {
    $multipage = ($curpage-$offset > 1 && $pages > $page? ' Home ': ').
    ($curpage > 1? ' ‹‹ prev ': ');
    for ($i = $from; $i <= $to; $i + +) {
    $multipage. = $i = = $curpage? ''. $i. '' :
    ". $i.";
    }

    $multipage. = ($curpage < $pages? ' Next page ›› ': ').
    ($to < $pages? ' Last ': ');
    $multipage = $multipage? ". $multipage. ': ';
    } else {

    $multipage = ($curpage-$offset > 1 && $pages > $page? ' Home ': ').
    ($curpage > 1? ' ‹‹ prev ': ');

    for ($i = $from; $i <= $to; $i + +) {
    $multipage. = $i = = $curpage? ''. $i. '' :
    ". $i.";
    }

    $multipage. = ($curpage < $pages? ' Next page ›› ': ').
    ($to < $pages? ' Last ': ');
    $multipage = $multipage? ". $multipage. ': ';
    }
    }
    return $multipage;
    }
    Not currently
    function Page_get_start ($page, $PPP, $totalnum) {
    $totalpage = Ceil ($totalnum/$PPP);
    $page = max (1, Min ($totalpage, intval ($page)));
    Return ($page-1) * $PPP;
    }
    Not currently
    function Js_page ($hiddenFrom, $page)
    {
    if ($hiddenFrom) {
    Return ' onclick=javascript:$ ("#page"). Val ("'. $page. '"); $ ("#". $hiddenFrom. '). Submit (); ';
    }
    }
    }



    ?>

    http://www.bkjia.com/PHPjc/633149.html www.bkjia.com true http://www.bkjia.com/PHPjc/633149.html techarticle this article to introduce to you a paginator PHP page program code, the need for friends to enter the reference. Code to copy code like this? PHP class Paginator {function __construct () {...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.