?
To avoid errors caused by duplicate inclusion of files, add a condition that determines whether the function exists:
if (!function_exists (Pageft)) {
Define function Pageft (), the meaning of three parameters is:
$totle: Total information;
$DISPLAYPG: The number of messages per page, set to default is 20;
$url: The links in pagination navigation are the same as this URL in addition to adding different query Information "page".
The default value should be set to the URL on this page (that is, $_server["Request_uri"]), but the right side of the default value can only be a constant, so the default value is set to an empty string, which is then set to the URL of this page inside the function.
function Pageft ($totle, $displaypg =20, $url = ') {
Define several global variables:
$page: current page number;
$firstcount: (database) The starting item of the query;
$pagenav: page navigation bar code, inside the function does not output it;
$_server: Required to read the URL "$_server[" Request_uri "]" on this page.
Global $page, $firstcount, $pagenav, $_server;
To give the function an external access to the "$DISPLAYPG" here, it is also set as a global variable. Pay attention to a variable redefined as a global variable, the original value is overwritten, so here it is assigned to the value.
$GLOBALS ["Displaypg"]= $displaypg;
if (! $page) $page = 1;
If $url uses the default, or null value, the assignment is the URL to this page:
if (! $url) {$url =$_server["Request_uri"];}
URL Analysis:
$parse _url=parse_url (/$url);
$url _query= $parse _url["Query"]; Query string to remove URL individually
if ($url _query) {
Because the URL may contain page number information, we need to remove it so that we can add a new page number information.
Here's a regular expression, refer to "Regular Expressions in PHP" (http://www.pconline.com.cn/pcedu/empolder/wz/php/10111/15058.html)
$url _query=ereg_replace ("(^|&) page= $page", "", $url _query);
The query string that replaces the original URL with the query string for the processed URL:
$url =str_replace ($parse _url["Query"), $url _query, $url);
Add page query information after the URL, but you want to assign a value:
if ($url _query) $url. = "&page"; else $url. = "page";
}else {
$url. = "? page";
}
Page number calculation:
$LASTPG =ceil ($totle/$DISPLAYPG); 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;