My original code, in the opinion of experts, the process may be clumsy, but it is very practical. Readers need to Thumbs up
/*---------------------------------------- -----------------------//
* Function description: paging function page($sql,$pagesize="30")
* $sql query statement (except limit, can have sorting or conditional restrictions)
* Such as select * from stu where time between "1" and "30";
* $pagesize The number of items displayed on each page
* ## can output the value of array $arr, the description is as follows:
* $arr["first"] Home page and address
* $arr["page_pre"] Previous page and address
* $ arr["all"] What page and total number of pages
* $arr["page_next"]Next page and address
* $arr["last"] Last page and address
* $ arr["pagelist"] page number list and address, showing the list of 4 pages before and after the current page
* $arr["query"] Statement $arr["query"] = mysql_query($sql)
* $arr[ "nums"] Total number of records
* 2006.09.06 by Kevin QQ:84529890
//-------------------------- ----------------------------------------*/
function page($sql,$pagesize ="30"){
global $arr,$PHP_SELF;
$query = mysql_query($sql);
$num = mysql_num_rows($query);
$ pagecount = ceil($num/$pagesize);
$page = $_GET["page"];
if(!$page) $page=1;
if($page>$pagecount) $page = $pagecount;
$offset = ($page-1)*$pagesize;
$sql.=" limit $offset , $pagesize";
$arr["query" ] = mysql_query($sql);
if($page>1){
$page_pre = $page-1;
$page_url = $PHP_SELF . "?page=".$page_pre ;
$arr["page_pre"] = "
Previous page|n";
}
if($ page<$pagecount){
$page_next = $page+1;
$page_url = $PHP_SELF . "?page=".$page_next;
$arr["page_next"] = "|< a href="".$page_url."">Next pagen";
}
$arr["all"] = "
".$page ."/". $pagecount . "Pagen";
$arr["first"] = "
Homepagen|";
$arr["last"] = "|
Last pagen";
$plfront="";
if($page<=5 && $page>=1){
for($ i=1;$i<=9;$i++){
$plfront.= "
".$i."< /a>";
}
}elseif($page>5 && $page<$pagecount-5){
for($i=$page-4;$i<$page+5; $i++){
$plfront.= " ".$i."";
}
}else{
for($i=$pagecount-8;$i<=$pagecount;$i++){
$plfront.= "
".$i."";
}
}
$arr["pagelist"] = $plfront." ";
$arr["nums"] = $num;
}