PHP paging reserved query Conditions

Source: Internet
Author: User
A simple paging. The query conditions can be retained. Custom paging address <? Phprequire_once ("Global. PHP "); function _ pageft ($ totle, $ displaypg = 20, $ url ='') {Global $ page, $ firstcount, $ pagenav, $ _ server; $ globals ["displaypg"] = $ displaypg; If (! $ Page) $ page = 1; if (! $ URL) {$ url = $ _ server ["request_uri"];} // URL analysis: $ parse_url = parse_url ($ URL ); // URL resolution $ url_query = $ parse_url ["query"]; // retrieve the URL query string if ($ url_query) {echo $ url_query. "<br>"; $ url_query = ereg_replace ("(^ | &) page = $ page", "", $ url_query ); $ url = str_replace ($ parse_url ["query"], "", $ URL); if ($ url_query) {$ URL. = $ url_query. "& page";} else {$ URL. = "page" ;}} else {$ URL. = "? Page ";}$ lastpg = Ceil ($ totle/$ displaypg); // The last page, also the total number of pages $ page = min ($ lastpg, $ page ); $ prepg = $ page-1; // Previous Page $ nextpg = ($ page = $ lastpg? 0: $ page + 1); // next page $ firstcount = ($ page-1) * $ displaypg; // start pagination navigation bar code: $ pagenav = "show the <B> ". ($ totle? ($ Firstcount + 1): 0 ). "</B>-<B> ". min ($ firstcount + $ displaypg, $ totle ). "</B> records, total $ totle records"; // if there is only one page, the function jumps out: if ($ lastpg <= 1) return false; $ pagenav. = "<a href = '$ url = 1'> homepage </a>"; if ($ prepg) $ pagenav. = "<a href = '$ url = $ prepg'> previous page </a>"; else $ pagenav. = "Previous Page"; if ($ nextpg) $ pagenav. = "<a href = '$ url = $ nextpg'> next page </a>"; else $ pagenav. = "back page"; $ pagenav. = "<a href = '$ url = $ lastpg'> last page </> "; // The drop-down Jump list. All page numbers are displayed cyclically: $ pagenav. = "to the <select name = 'topage' size = '1' onchange = 'window. location = \ "$ url = \" + this. value '> \ n "; for ($ I = 1; $ I <= $ lastpg; $ I ++) {if ($ I = $ page) $ pagenav. = "<option value = '$ I' selected> $ I </option> \ n"; else $ pagenav. = "<option value = '$ I'> $ I </option> \ n" ;}$ pagenav. = "<lect> page, $ lastpg page in total" ;}$ page =$ _ Get ["page"]; $ result = $ db-> query ("select * From regsip"); $ Total = My SQL _num_rows ($ result); // call pageft (). 10 messages are displayed on each page (this parameter can be omitted when the default value is 20). Use the URL on this page (default, so omitted ). _ Pageft ($ total, 5); echo $ pagenav; $ result = $ db-> query ("select * From regsip limit $ firstcount, $ displaypg "); while ($ ROW = mysql_fetch_array ($ result) {?> <Table width = 500 border = "1" cellpadding = "5" cellspacing = "1" bgcolor = "# add3ef"> <tr bgcolor = "# eff3ff"> <TD> name: <? = $ Row [loginname]?> </TD> </tr> </table> <?}?>

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.