This article mainly introduces the complete php paging function instance code, and uses a more detailed comment to illustrate the PHP paging method and principle, if you need this function, you can refer to this article to share the complete php paging function instance code. Share it with you for your reference.
The specific function code is as follows:
<? Php/** Created on 2011-07-28 * usage: require_once ('mypage. php '); $ result = mysql_query ("select * from mytable", $ myconn); $ total = mysql_num_rows ($ result); // pageDivide ($ total, 10); // call the paging function // database operation $ result = mysql_query ("select * from mytable limit $ sqlfirst, $ shownu", $ myconn ); while ($ row = mysql_fetch_array ($ result )){//... your operation} echo $ pagecon; // output the paging navigation content */if (! Function_exists ("pageDivide") {# $ total information # $ shownu display quantity, default 20 # $ url link to this page function pageDivide ($ total, $ shownu = 20, $ url = '') {# $ page current page # $ sqlfirst mysql database start item # $ pagecon paging navigation content global $ page, $ sqlfirst, $ pagecon, $ _ SERVER; $ GLOBALS ["shownu"] = $ shownu; if (isset ($ _ GET ['Page']) {$ page = $ _ GET ['Page'];} else $ page = 1; # if $ url uses the default value, that is, null value, the value is URLif (! $ Url) {$ url = $ _ SERVER ["REQUEST_URI"] ;}# URL Analysis $ parse_url = parse_url ($ url ); @ $ url_query = $ parse_url ["query"]; // The question mark? After the content if ($ url_query) {$ url_query = preg_replace ("/(&?) (Page = $ page)/"," ", $ url_query); $ url = str_replace ($ parse_url [" query "], $ url_query, $ url ); if ($ url_query) {$ url. = "& page";} else $ url. = "page";} else $ url. = "? Page "; # page number calculation $ lastpg = ceil ($ total/$ shownu); // last page, total page number $ page = min ($ lastpg, $ page ); $ prepg = $ page-1; // Previous page $ nextpg = ($ page = $ lastpg? 0: $ page + 1); // Next page $ sqlfirst = ($ page-1) * $ shownu; # start pagecon navigation content $ pagecon = "show no ". ($ total? ($ Sqlfirst + 1): 0). "-". min ($ sqlfirst + $ shownu, $ total). "records, total$ TotalRecord "; if ($ lastpg <= 1) return false; // if only one page exists, if ($ page! = 1) $ pagecon. = "homepage"; else $ pagecon. = "homepage"; if ($ prepg) $ pagecon. = "previous page"; else $ pagecon. = "previous page"; if ($ nextpg) $ pagecon. = "back page"; else $ pagecon. = "back page"; if ($ page! = $ Lastpg) $ pagecon. = "Last page"; else $ pagecon. = "Last page"; # drop-down navigation list, listing all page numbers cyclically $ pagecon. ="\ N "; for ($ I = 1; $ I <= $ lastpg; $ I ++) {if ($ I = $ page) $ pagecon. ="$ I\ N "; else $ pagecon. ="$ I\ N ";}$ pagecon. ="Page, total $ lastpg page ";}} else die ('pagedivide () function with the same name already exists! ');?>
I believe this article provides some reference value for PHP programming.