Php paging function complete instance code

Source: Internet
Author: User
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.

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.