Common PHP Wrapper Paging tool class

Source: Internet
Author: User
Paging is basically the use of each project, so, it is packaged into a tool class, and then directly call on it (although the TP frame is often powerful, but it is also possible to seal one.) ), which saves time and effort and earns ' Gongfen '.

I sealed this page of the tool class is also relatively complete, there are home, previous page, the next page, the end and the number of optional number of pages (that is, when the page is very large, only show the number of parameters passed in), you can also choose whether to use the drop-down page function according to the requirements.

<?php/** * Pagination Tool class */class page{/** * Returns the required string for pagination * @param $pageNum int Display page number * @param $pageCount int total page numbers * @param $url String The current page number path * @param $Count the number displayed in the string page list * @param $selected bool Whether the drop-down box selection function is turned on.    The default does not turn on the * return $strpage string Paging String */function ShowPage ($pageNum, $pageCount, $url, $Count = 5, $selected = False) { $pageMaxVal = $Count The -1;//page number reaches the maximum, the difference between the first page number and the maximum page number in the page list $pageMiddleVal = Ceil ($Count/2);//The median value of the number of pages to be displayed $pageMid    Dlecha = Floor ($Count/2);//The difference between the current page number and the first page number, based on the need to display page numbers//determine if the URL already exists? if (!strpos ($url, '? '))      {//does not exist?    $url. = '? ';    }else{$url. = ' & ';     }//Home $strpage = "<a href= ' {$url}num=1 ' > Home </a>"; Prev $preNum = $pageNum > 1?     $pageNum-1:1; Cancels the function of the previous page button when the page number is first $strpage. = $pageNum = = 1?     "<a class= ' unshow > Prev </a>": "<a href= ' {$url}num={$preNum} ' > Prev </a>"; The first page number in the displayed page number list $startPage = $pageNum > $pageMiddleVal? $pageNum-$pageMiddlecha:1; Start Page maximum = total number of pages-4 if ($pageCount-$pageMaxVal > 0 && $startPage > $pageCount-$pageMaxVal) {$sta    Rtpage = $pageCount-$pageMaxVal; }//Display the last page number in the list of page numbers $endPage = $startPage < ($pageCount-$pageMaxVal)?     $startPage + $pageMaxVal: $pageCount; Median digit number for ($i = $startPage; $i <= $endPage; $i + +) {if ($i = = $pageNum) {$strpage. = "<span> $i </span      > ";      }else{$strpage. = "<a href= ' {$url}num= $i ' > $i </a>"; }}//next page $nextNum = $pageNum < $pageCount?     $pageNum + 1: $pageCount; Cancels the function of the next page button when the page number is the last page $strpage. = $pageNum = = $pageCount?     "<a class= ' unshow ' > Next </a>": "<a href= ' {$url}num={$nextNum} ' > Next </a>";     Last $strpage. = "<a href= ' {$url}num={$pageCount} ' > End </a>";     Total pages $strpage. = "Total pages: {$pageCount}"; Determines whether the page number function is selected if ($selected) {//Selected $strpage. = "Current page: <select onchange=\" location.href= ' {$url}num= ' + this.value \ ">"; for ($i = 1; $i <= $pageCount; $i + +) {if ($i = = $pageNum) {$strpage. = "<option value= ' $i ' selected          = ' selected ' > $i </option> ";          }else{$strpage. = "<option value= ' $i ' > $i </option>";    }} $strpage. = "</select>";  } return $strpage; } }

Next should be PO finished MySQL remaining knowledge bar, I hope you continue to pay attention.

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.

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.