function Outpege ($ps tutorial, $page)
{
$ps Cumulative number of information $page the current page number $max the maximum number of lists $min the minimum value of the list
$max = ($page >= 5)? $page +5:10;
if ($max > $ps) $max = $ps;
$min = ($page-5);
if ($min <1) $min = 1;
if ($page >1) $pagelist = "<a href="? page=1 "> Home </a>";
for ($i = $min; $i <= $max; $i + +) {
$pagelist. = ($i!= $page)? "<a href="? page={$i} ">{$i}</a>": "<a href=" # ">{$page}</a>";
}
$pagelist. = ($page >= $ps)? ': "<a href="? page={$ps} "> Last </a>";
return $pagelist;
}
Method Two
/**
* Show Paging function
* Records Total records, currentpage current pages, rows per page record number, listpage page number list length.
*/
function ShowPage ($records, $currentpage, $rows =20, $listpages =7) {
if ($records <1) return ";
if ($rows <1) $rows = 20;
if ($listpages <3) $listpages = 7;
$action =$_server[' query_string ']; Get the Address bar? After the content
if ($action) {//Will page= ... Removed from the content
$action =preg_replace ("/&page[^&]*/", "", $action);
$action =preg_replace ("/page[^&]*&*/", "", $action);
}
if ($action) $action. = ' & ';
$maxpage =ceil ($records/$rows); The maximum number of pages can be obtained by rounding.
$middlepage =floor ($listpages/2); The rounding method takes half of the number of pages to be displayed.
if ($currentpage <1| | $currentpage > $maxpage) $currentpage = 1;
$startpage = $currentpage-$middlepage;
if ($maxpage-$currentpage <= $middlepage) $startpage = $maxpage-$listpages;
if ($startpage <2) $startpage = 2; Start Page calculation complete
$endpage = $startpage + $listpages;
if ($endpage > $maxpage) $endpage = $maxpage; End Page Calculation complete
if ($currentpage!=1) {
$pagestr = "<a href="? {$action}page=1 ' ><span>1</span></a> ';
}else{
$pagestr = "<span>1</span>";
}
Home 1 2 3 4 5 6 7 8
last