PHP implementation of the beautiful pagination method _php Tutorial

Source: Internet
Author: User
Pagination page numbering display algorithm

Copy CodeThe code is as follows:
/**
* Get HTML content for pagination
* @param integer $page current page
* Total number of pages $pages @param integer
* @param string $url The last page of the URL address appended with ' &page=x ' after the URL
*
* @return string HTML content;
*/
public static function getpagehtml ($page, $pages, $url) {
Maximum number of pages to display
$_pagenum = 5;
The current page is less than 1 is 1
$page = $page <1?1: $page;
The current page is greater than the total number of pages
$page = $page > $pages? $pages: $page;
The current page is a small page
$pages = $pages < $page? $page: $pages;

Calculate Start Page
$_start = $page-floor ($_PAGENUM/2);
$_start = $_start<1? 1: $_start;
Calculate End Page
$_end = $page + Floor ($_PAGENUM/2);
$_end = $_end> $pages? $pages: $_end;

The number of page numbers currently displayed is not large enough to adjust the left and right
$_curpagenum = $_end-$_start+1;
Left adjustment
if ($_curpagenum<$_pagenum && $_start>1) {
$_start = $_start-($_pagenum-$_curpagenum);
$_start = $_start<1? 1: $_start;
$_curpagenum = $_end-$_start+1;
}
Right adjustment
if ($_curpagenum<$_pagenum && $_end< $pages) {
$_end = $_end + ($_pagenum-$_curpagenum);
$_end = $_end> $pages? $pages: $_end;
}

$_pagehtml = '

      ';
      /*if ($_start = = 1) {
      $_pagehtml. = '
    • «
    • ';
      }else{
      $_pagehtml. = '
    • «
    • ';
      }*/
      if ($page >1) {
      $_pagehtml. = '
    • «
    • ';
      }
      for ($i = $_start; $i <= $_end; $i + +) {
      if ($i = = $page) {
      $_pagehtml. = '
    • '. $i. '
    • ';
      }else{
      $_pagehtml. = '
    • '. $i. '
    • ';
      }
      }
      /*if ($_end = = $pages) {
      $_pagehtml. = '
    • »
    • ';
      }else{
      $_pagehtml. = '
    • »
    • ';
      }*/
      if ($page <$_end) {
      $_pagehtml. = '
    • »
    • ';
      }
      $_pagehtml. = '
';
Echo $_pagehtml;
}

http://www.bkjia.com/PHPjc/755839.html www.bkjia.com true http://www.bkjia.com/PHPjc/755839.html techarticle pagination page number display algorithm copy code code as follows:/** * Get HTML content for pagination * @param integer $page current page * @param integer $pages Total pages * @param string $url jump ur ...

  • Related Article

    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.