// In order to avoid repeating the included file, the incorrect is added, and the determination function is existing: if (! @ Function_exists (pageft)) {// definition function Pageft (), the meaning of the three parameters is: // $ Totle: Total information; // $ displayPG: The number of information per page is set, here is the default is 20; // $ URL: Sub-navigation links, in addition to adding different query information "Page" and this URL the same. // The default value This is set to this page URL (ie $ _server ["Request_uri"), but set only the default value can only be constant, so the default value is set to an empty string, and then set to this in the function. Page URL. Function Pageft ($ TOTLE, $ DISPLAYPG = 20, $ URL = '') {
// Define several global variables: // $ page: current page number; // $ firstcount: start items of queries; // $ PAGENAV: page navigation bar code, the function is not output inside; // $ _SERVER: Read this page URL "$ _ server [" Request_uri "]" must. Global $ Page, $ FIRSTCOUNT, $ PAGENAV, $ _ Server
/ / In order to access the "$ DISPLAYPG" here, it is also set to global variables. Note that a variable is redefined as a global variable, the original value is overwritten, so it is re-assigned here. $ Global ["displaypg"] = $ displaypg;
IF (! $ Page) $ Page = 1;
// If the $ URL uses the default, the null value, the value is this page URL: if (! $ URL) {@ $ URL = $ _ Server ["Request_uri"];}
// URL analysis: $ parse_url = parse_url ($ URL); @ $ url_query = $ parse_URL ["query"]; // Remove the URL query string IF ($ URL_QUERY) {// Because the URL may contain the page number Information, we have to remove it in order to add new page number information. // This is used here, please refer to "Regular Expression in PHP" (http://www.pconline.com.cn/pcedu/empolder/wz/php/10111/15058.html) $url_Query=REG_REPLACE ("(^ | &) Page = $ Page", "", $ URL_QUERY);
// Replace the query string of the original URL after processing: $ url = str_replace ($ PARSE_URL ["Query"], $ URL_QUERY, $ URL);
// After the URL adds Page query information, but to assign the value: if ($ URL_QUERY) $ URL. = "& Page"; Else $ URL. = "Page";} else {$ URL. = "Page";
// Table Calculation: $ lastpg = CEIL ($ TOTLE / $ DISPLAYPG); // Last page, the total number of pages $ Page = min ($ Lastpg, $ Page); $ prePg = $ PAGE-1; // Previous Page $ nextpg = ($ page == $ lastpg? 0: $ page 1); // Next $ firstcount = ($ PAGE-1) * $ displayPG; // Start Page Navigation Code: $ Pagenav = " Showing No. B> ". ($ TOTLE? ($ FIRSTCOUNT 1): 0)." B> - ". Min ($ FIRSTCOUNT $ DisplayPG, $ TOTLE)." B> record Total $ TOTLE record
// If only one page is jumped out of the function: IF ($ lastpg <= 1) Return False;
$ Pagenav. = " "; ELSE $ PAGENAV. =" Page "; if ($ nextpg) $ Pagenav. =" page "; Else $ Pagenav. =" Page "; $ PAGENAV. =" Last ""
// Drop the jump list, list all the page numbers: $ PAGENAV. = "To the