1 2
3 function _PAGEFT($totle, $displaypg = 20, $url = '') {
4
5 global $page, $firstcount, $pagenav, $_SERVER;
6
7 $GLOBALS["displaypg"] = $displaypg;
8
9 if (!$page)
$page = 1;
if (!$url) {
$url = $_SERVER["REQUEST_URI"];
}
//URL analysis:
$parse_url = parse_url($url);
$url_query = $parse_url["query"]; //Get the URL query string separately
if ($url_query) {
$url_query = ereg_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" ;
}
$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 paging navigation bar code:
$pagenav = "Display the
" . ($totle ? ($firstcount +1) : 0) . " -
" . min($firstcount + $displaypg, $totle) . " records, total $totle records";
//If there is only one page, jump out of the function:
if ($lastpg <= 1)
return false;
$pagenav .= "
Homepage ";
if ($ prepg)
$pagenav .= "
Previous page ";
else
$pagenav .= " Previous page";
if ($nextpg)
$pagenav .= "
Next page ";
else
$pagenav .= " Next page";
$pagenav .= "
Last page ";
//Pull down jump list, loop through all page numbers :
$pagenav .= "Go to
n"; for ($i = 1; $i <= $lastpg; $i++) { if ($i == $page) $pagenav .= "$ i n"; else $pagenav .= "$i n"; } $pagenav . = " pages of $lastpg";
}
include("conn.php");
$result=mysql_query("SELECT * FROM `test`");
$total=mysql_num_rows($result);
//Call pageft(), display 10 pieces of information per page (when using the default 20, you can omit this parameter), use this page URL (default, so omit it ).
_PAGEFT($total,5);
echo $pagenav;
$result=mysql_query("SELECT * FROM `test` limit $firstcount,$displaypg ");
while($row= mysql_fetch_array($result)){
echo "
".$row[name]." | ".$row[sex]; } ?>