Php _ paging code-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? Phpphp Article _ paging code in order to avoid repeated file inclusion errors, a condition is added to determine whether a function exists: if (! Function_exists (pageft) {functionpageft ($ totle, $ displaypg20, $ url) {defines several global variables: $ page: Current page number; $ firstcount :( database) The start item of the query; script ec (2); script

// To avoid errors caused by repeated file inclusion, the following conditions are added to determine whether a function exists:
If (! Function_exists (pageft )){
/
Function pageft ($ totle, $ displaypg = 20, $ url = ''){

// Define several global variables:
// $ Page: Current page number;
// $ Firstcount: (database) The start item of the query;
// $ Pagenav: page navigation bar code, which is not output in the function;
// $ _ SERVER: required to read the URL "$ _ SERVER [" REQUEST_URI "]" on this page.
Global $ page, $ firstcount, $ pagenav, $ _ SERVER;


$ GLOBALS ["displaypg"] = $ displaypg;

If (! $ Page) $ 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"]; // retrieve the query string of the URL separately.
If ($ url_query ){

$ Url_query = ereg_replace ("(^ | &) page = $ page", "", $ url_query );


$ Url = str_replace ($ parse_url ["query"], $ url_query, $ url );

// Add page after the URL to query the information, but the value to be assigned is:
If ($ url_query) $ url. = "& page"; else $ url. = "page ";
} Else {
$ Url. = "? Page ";
}

// Page number calculation:
$ 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 the paging navigation bar code:
$ Pagenav = "display". ($ Totle? ($ Firstcount + 1): 0 )."-". Min ($ firstcount + $ displaypg, $ totle )."A total of $ totle records
";

// If there is only one page, the function will jump out:
If ($ lastpg <= 1) return false;

$ Pagenav. = "Homepage ";
If ($ prepg) $ pagenav. = "Previous Page"; else $ pagenav. = "Previous Page ";
If ($ nextpg) $ pagenav. = ""; else $ pagenav. = "";
$ Pagenav. = "last page ";

// Pull-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 ";
}
}
?> [/Quote]


[Quote]

$ SQL = "select * from database name ";
$ Conn = mysql_query ($ SQL );
$ Total = mysql_num_rows ($ conn );
Pageft ($ total, 7); // number of records displayed on one page
$ Result = mysql_query ("select * from database name order by ID No. asc limit $ firstcount, $ displaypg ");

Echo $ pagenav; // output page
?>

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.