Php paging function example code sharing _ PHP Tutorial

Source: Internet
Author: User
Php paging function sample code sharing. Share a php paging function code example. using this function to implement paging code is good. Code, php paging function. Copy the code as follows :? Php ** Createdon2011-07-28 * Author: LKK shares a php paging function code example, using this function to implement paging code is very good.

Code, php paging function.

The code is as follows:


/*
* Created on 2011-07-28
* Author: LKK, http://lianq.net
* Usage:
Require_once ('mypage. php ');
$ Result = mysql_query ("select * from mytable", $ myconn );
$ Total = mysql_num_rows ($ result); // The total number of retrieved information.
PageDivide ($ total, 10); // call the paging function

// Database operations
$ Result = mysql_query ("select * from mytable limit $ sqlfirst, $ shownu", $ myconn );
While ($ row = mysql_fetch_array ($ result )){
... Your operations
}
Echo $ pagecon; // The output page navigation content.
*/

If (! Function_exists ("pageDivide ")){
# $ Total information
# $ Shownu display quantity. the default value is 20.
# $ Url link to this page
Function pageDivide ($ total, $ shownu = 20, $ url = ''){

# $ Current page number
# $ 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 assigned to the URL of the current page.
If (! $ Url) {$ url = $ _ SERVER ["REQUEST_URI"];}

# URL analysis
$ Parse_url = parse_url ($ url );
@ $ Url_query = $ parse_url ["query"]; // The question mark? Subsequent 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
$ Page = min ($ lastpg, $ page );
$ Prepg = $ page-1; // Previous page
$ Nextpg = ($ page = $ lastpg? 0: $ page + 1); // Next page
$ Sqlfirst = ($ page-1) * $ shownu;

# Start paging navigation content
$ Pagecon = "display number". ($ total? ($ Sqlfirst + 1): 0). "-". min ($ sqlfirst + $ shownu, $ total). "records, total$ TotalRecords ";
If ($ lastpg <= 1) return false; // jumps out if there is only one page

If ($ page! = 1) $ pagecon. = "homepage"; else $ pagecon. = "homepage ";
If ($ prepg) $ pagecon. = "previous page"; else $ pagecon. = "previous page ";
If ($ nextpg) $ pagecon. = ""; else $ pagecon. = "";
If ($ page! = $ Lastpg) $ pagecon. = "Last page"; else $ pagecon. = "Last page ";

# Pull-down Jump 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 ";

}
} The else die ('pagedivide () function with the same name already exists! ');
?>

Bytes. Code, php paging function. The code is as follows :? Php/** Created on 2011-07-28 * Author: LKK...

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.