[Php]/* Idea 1. Get the URL in the address bar 2. Analyze the query section in the URL-that is? Part 3. query is analyzed as an array. 4. + 1,-1 in the array to form two new arrays 5. concatenate the new array into the query part and combine the previous Page and next Page connection address * // The number of all lines in the paging class Page {public $ total, retrieve public $ prePage = 10 from the database; // number of entries per page protected $ curr = 1; // default current page number public function _ construct ($ total, $ prePage = '') {$ this-> total = $ total; // place the total entry information in the total attribute if ($ prePage> 0) {$ this-> prePage = $ prePage; // place the number of pages per page in the perPage attribute} // calculate the current page number if (isset ($ _ GET ['page']) & ($ _ GET ['Pa Ge '] + 0)> 0) {$ this-> curr = $ _ GET ['page'] + 0 ;}// main function public function showPage () {if ($ this-> total <= 0) {return ''; // if the total number of entries is <= 0, an empty string is returned.} $ cnt = ceil ($ this-> total/$ this-> prePage); // calculates the total number of pages, perform an integer // based on the current page, calculate the previous page, next page/* analyze the url. What are the situations? Xx. php xx. php? Id = 5 xx. php? Page = 3 xx. php? Id = 5 & page = 3 * // The final generated URL must contain page = N $ url = $ _ SERVER ['request _ URI ']; $ parse = parse_url ($ url); // put the URL analysis result in the array // print_r ($ parse); // ensure that the parameter contains page if (! Isset ($ parse ['query']) {$ parse ['query'] = 'page = '. $ this-> curr;} // analyze the query string into an array and make sure that the page option parse_str ($ parse ['query'], $ parms) is available again; if (! Array_key_exists ('page', $ parms) {$ parms ['page'] = $ this-> curr;} // test the preceding four conditions, the page parameter can generate // print_r ($ parms); // you can determine whether there are other parameters besides page (if (count ($ parms) = 1) {$ url = $ parse ['path']. '? ';} Else {unset ($ parms ['page']); $ url = $ parse ['path'].'? '. Http_build_query ($ parms ). '&';} // echo $ url $ prev = $ this-> curr-1; $ next = $ this-> curr + 1; // homepage $ indexLink = '<a href = "'. $ url. 'page = '. 1. '"> homepage </a>'; // previous page if ($ prev <1) {$ prevLink = '';} else {$ prevLink = '<a href = "'. $ url. 'page = '. $ prev. '"> previous page </a>';} // next page if ($ next> $ cnt) {$ nextLink = '';} else {$ nextLink = '<a href = "'. $ url. 'page = '. $ next. '"> next page </a>';} // last page $ lastLink = '<a href = "'. $ url. 'page = '. $ cnt. '"> last page </a>'; // echo $ indexLink. ''. $ prevLink. ''. $ nextLink. ''. $ lastLink; // Previous Page, 1 2 3 4 5 next page $ start = $ this-> curr-(5-1)/2; // calculate the start page number on the left $ end = $ this-> curr + (5-1)/2; // calculate the start page number on the right. // If the start page on the left is displayed, if the value is less than 1, add the less than 1 part to the right if ($ start <1) {$ end + = (1-$ start); $ start = 1; // modify start = 1 if ($ end> $ cnt) {$ end = $ cnt ;}/// Add the excess part on the right, add to left if ($ end> $ cnt) {$ start-= ($ end-$ cnt); $ end = $ cnt; if ($ start <1) {$ start = 1 ;}/// Number of outgoing page numbers in a loop $ pageStr = ''; for ($ I = $ start; $ I <= $ end; $ I ++) {if ($ I ==$ this-> curr) {$ pageStr. = $ I; continue;} $ pageStr. = '<a href = "'. $ url. 'page = '. $ I. '"> '. $ I. '</a>';} return $ indexLink. $ prevLink. $ pageStr. $ nextLink. $ lastLink ;}}$ page = new Page (); echo $ page-> showPage ();