<?phpphp Article _ Pagination Code
To avoid errors caused by duplicate inclusion of files, add a condition that determines 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 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;
$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) {
$url _query=ereg_replace ("(^|&) page= $page", "", $url _query);
$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;
To start the pager bar code:
$pagenav = "Show <B>". ($totle? ($firstcount + 1): 0). " </B>-<B> ". Min ($firstcount + $DISPLAYPG, $totle)." </B> Records, a total of $totle records <BR> ";
If only one page jumps out of the function:
if ($lastpg <=1) return false;
$pagenav. = "<a href= ' $url =1 ' > Home </a>";
if ($PREPG) $pagenav. = "<a href= ' $url = $prepg ' > front page </a>"; else $pagenav. = "front page";
if ($NEXTPG) $pagenav. = "<a href= ' $url = $nextpg ' > Back page </a>"; else $pagenav. = "Back Page";
$pagenav. = "<a href= ' $url = $lastpg ' > Last </a>";
Drop-down Jump List, looping through all page numbers:
$pagenav. = "to <select name= ' topage ' size= ' 1 ' onchange= ' window.location=\" $url =\ "+this.value ' >\n";
for ($i =1; $i <= $lastpg; $i + +) {
if ($i = = $page) $pagenav. = "<option value= ' $i ' selected> $i </option>\n";
else $pagenav. = "<option value= ' $i ' > $i </option>\n";
}
$pagenav. = "</select> 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 record bars displayed on one page
$result = mysql_query ("SELECT * from database name ORDER by ID number ASC limit $firstcount, $DISPLAYPG");
Echo $pagenav; Output page Paging
?>