Common PHP encapsulation paging tools and paging tools
Paging is basically used by every project. Therefore, you can encapsulate it into a tool class and directly call it later (although the TP framework is very powerful, however, you cannot seal one by yourself .), This saves both time and effort and generates 'employee scores '.
The paging tool class I provided is still complete, including the Home Page, Previous Page, next page, last page, and number of available pages (that is, when there are many pages, display only the number passed in according to the parameter), you can also choose whether to use the drop-down navigation page function as required.
<? Php/*** paging tool class */class page {/*** return the string required for paging * @ param $ page number displayed by pageNum int * @ param $ pageCount int total page number *@ param $ url string current page number path * @ param $ Count number displayed in the string page number list * @ param $ selected bool whether to enable the drop-down box selection function. * Return $ strpage string paging string */function showPage ($ pageNum, $ pageCount, $ url, $ Count = 5, $ selected = false) is disabled by default) {$ pageMaxVal = $ Count-1; // the difference between the first page number and the maximum page number in the page number list $ pageMiddleVal = ceil ($ Count/2 ); // returns the median value based on the number of pages to be displayed. $ pageMiddleCha = floor ($ Count/2 ); // determine whether the url already exists based on the difference between the current page number and the first page number that needs to be displayed? If (! Strpos ($ url ,'? ') {// Does not exist? $ Url. = '? ';} Else {$ url. = '&';} // homepage $ strpage = "<a href = '{$ url} num = 1'> homepage </a> "; // Previous Page $ preNum = $ pageNum> 1? $ PageNum-1: 1; // when the page number is the first page, cancel the previous page button function $ strpage. = $ pageNum = 1? "<A class = 'unshow '> previous page </a> ": "<a href = '{$ url} num = {$ preNum}'> previous page </a> "; // The first page in the displayed page number list $ startPage = $ pageNum> $ pageMiddleVal? $ PageNum-$ pageMiddleCha: 1; // maximum starting page number = total page number-4 if ($ pageCount-$ pageMaxVal> 0 & $ startPage> $ pageCount-$ pageMaxVal) {$ startPage = $ pageCount-$ pageMaxVal;} // The last page number in the displayed page number list $ endPage = $ startPage <($ pageCount-$ pageMaxVal )? $ StartPage + $ pageMaxVal: $ pageCount; // the page number of the intermediate 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; // when the page number is the last page, the function of the next page button is canceled $ strpage. = $ pageNum = $ pageCount? "<A class = 'unshow '> next page </a> ": "<a href = '{$ url} num = {$ nextNum}'> next page </a>"; // last page $ strpage. = "<a href = '{$ url} num = {$ pageCount}'> last page </a>"; // total number of pages $ strpage. = "total page number: {$ pageCount}"; // determines whether the page number is selected. if ($ selected) {// select $ strpage. = "Current page number: <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 ;}}
I hope you will continue to pay attention to the remaining MySQL knowledge.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.