PHP Tutorial page code
To avoid errors caused by repeating the inclusion of a file, add a condition that determines whether the function exists:
$page = $_get[page];
if (!function_exists (Pageft)) {
Define the function Pageft (), the meaning of the three parameters is:
$totle: Total information;
$DISPLAYPG: The number of messages displayed per page, which is set to default is 20;
$url: The link in the pager is the same as this one except for adding different query Information "page".
The default value should be set to the page URL (that is, $_server["Request_uri"]), but the default value can only be constant to the right, so the default value is set to an empty string, which is then set to the page URL inside the function.
function Pageft ($totle, $displaypg =20, $url = ") {
Define several global variables:
$page: current page number;
$firstcount: The starting item for the (database tutorial) query;
$pagenav: the page navigation bar code, inside the function does not output it;
$_server: Read this page url "$_server[" Request_uri "]" must.
Global $page, $firstcount, $pagenav, $_server;
For the outside of the function to have access to the "$DISPLAYPG" here, it is also set as a global variable. Note that when a variable is redefined as a global variable, the original value is overwritten, so it is re-assigned.
$globals ["Displaypg"]= $displaypg;
if (! $page) $page = 1;
If you use the default, or null value, for the value of the page, the URL is assigned:
if (! $url) {$url =$_server["Request_uri"];}
URL Analysis:
$parse _url=parse_url ($url);
$url _query= $parse _url["Query"]; Query string to take out the URL separately
if ($url _query) {
Because the URL may contain the page number information, we want to remove it, in order to add the new page number information.
Regular expressions are used here, please refer to "Regular Expressions in PHP"
$url _query=preg_replace ("/(^|&) page= $page/", "", $url _query);
Replace the query string for the processed URL with the query string for the original URL:
$url =str_replace ($parse _url["Query"], $url _query, $url);
Add page query information after URL, but to assign value:
if ($url _query) $url. = "&page"; else $url. = "page";
}else {
$url. = "? page";
}
Page Count:
$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;
Start Page navigation bar code:
$pagenav = "Show Section ". ( $totle? ($firstcount + 1): 0). " -". Min" ($firstcount + $DISPLAYPG, $totle). " Records, Total $totle records";
If only one page jumps out of the function:
if ($lastpg <=1) return false;
$pagenav. = "Home";
if ($PREPG) $pagenav. = "front page"; else $pagenav. = "front page";
if ($NEXTPG) $pagenav. = "Back Page"; else $pagenav. = "Back Page";
$pagenav. = "Last";
Drop-down Jump List, looping through all page numbers:
$pagenav. = "Ton "; for ($i =1; $i <= $lastpg; $i + +) {if ($i = = $page) $pagenav. ="$in "; else $pagenav. ="$in ";} $pagenav. = "Page, total $lastpg page ";
}
}
http://www.bkjia.com/PHPjc/632026.html www.bkjia.com true http://www.bkjia.com/PHPjc/632026.html techarticle PHP Tutorial Pagination Code//In order to avoid repeating the inclusion of the file caused by errors, added to determine whether the function exists condition: $page = $_get[page]; if (!function_exists (Pageft)) {//define function ...