Simple and practical php paging Function Code

Source: Internet
Author: User
Welcome to the Linux community forum, and interact with 2 million technical staff to enter a simple and practical php paging function. The page navigation can be left blank by default, and then set the URL on this page within the function. Code :? Php *** page ** @ category function * @ param $ totle: Total Information * @ param $ displaypg: Number of information displayed on each page. Set this parameter here.

Welcome to the Linux community forum and interact with 2 million technical staff> enter a simple and practical php paging function. By default, this page URL can be set inside the function. code :? Php/*** paging * @ category function * @ param $ totle: Total Information * @ param $ displaypg: Number of information displayed on each page. Set here

Welcome to the Linux community forum and interact with 2 million technicians>

A simple and practical php paging function, which can be left blank by default in the paging navigation, and then set the URL of this page within the function.

Code:

  

/**

* Paging

* @ Category

* @ Param $ totle: Total Information

* @ Param $ displaypg: Number of information displayed on each page. The default value is 20;

* @ Param $ url: links in the paging navigation, except for adding different Query Information "page", are all the same as the URL. The default value should be the URL of the current page (that is, $ _ SERVER ["REQUEST_URI"]), but the right side of the default value can only be a constant, so this default value is set to an empty string, set this page URL in the function.

* @ Return string

*/

Function pageft ($ totle, $ displaypg = 20, $ url = ''){

$ Page = fget ("page", 1 );

$ Url = empty ($ url )? $ _ SERVER ["REQUEST_URI"]: $ url;

// URL analysis:

$ Parse_url = parse_url ($ url );

$ Url_query = isset ($ parse_url ["query"])? $ Parse_url ["query"]: ""; // retrieve the query string of the URL separately.

If ($ url_query ){

$ Url_query = preg_replace ("/page = [^ &] * [&]? /I "," ", $ url_query );

$ Url = str_replace ($ parse_url ["query"], $ url_query, $ url); // Replace the query string of the processed URL with the query string of the original URL

$ Url. = "& page"; // Add page information after the URL, but the value to be assigned

} Else {

$ Url. = "? Page ";

}

// Page number calculation:

$ Lastpg = ceil ($ totle/$ displaypg); // The last page, also the total number of pages

$ Lastpg = $ lastpg? $ Lastpg: 1; // no entries are displayed. Set the last page to 1.

$ Page = min ($ lastpg, $ page );

$ Firstcount = ($ page-1) * $ displaypg;

// If there is only one page, the function will jump out, and no paging text will be displayed (for backup)

// If ($ lastpg <= 1) return false;

// Start the paging navigation bar code

$ Pagenav = "show th". ($ totle? ($ Firstcount + 1): 0). "/". min ($ firstcount + $ displaypg, $ totle ). "Records, total $ totle records
";

$ Pagenav. = "Homepage ";

If ($ prepg) $ pagenav. = "Previous Page"; else $ pagenav. = "Previous Page ";

If ($ nextpg) $ pagenav. = ""; else $ pagenav. = "";

$ Pagenav. = "last page ";

// Drop-down Jump list, listing all page numbers cyclically

$ Pagenav. ="\ N ";For ($ I = 1; $ I <= $ lastpg; $ I ++ ){If ($ I = $ page ){$ Pagenav. ="$ I\ N ";} Else {$ Pagenav. ="$ I\ N ";}}$ Pagenav. ="Page, total $ lastpg page ";

// Organization Return Value

$ Re_str ['limit'] = "limit {$ firstcount}, {$ displaypg }";

$ Re_str ['str'] = $ pagenav;

Return $ re_str;

}

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.