Copy the code The code is as follows:
My own original code. In the opinion of experts, the process may be a bit clumsy, but it is very practical. Viewers should give it a thumbs up
/*---------- -------------------------------------------------- --//
* Function description: paging function page($sql,$pagesize="30")
* $sql query statement (except limit, which can be sorted or conditionally restricted)
* Such as select * from stu where time between "1" and "30";
* $pagesize The number of displayed items per page
* ## can output the value of the array $arr, the description is as follows:
* $arr["first"] Home page and address
* $arr ["page_pre"] Previous page and address
* $arr["all"] Which 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"] = "|Next pagen";
}
$arr["all"] = "".$page ." /". $pagecount . "pagen";
$arr["first"] = "Homepage$arr["last"] = "|Last pagen";
$plfr
if($page<=5 && $page>=1){
for($i=1;$i<=9;$i++){
$plfront.= " ".$i."";
}
}elseif($page>5 && $page<$pagecount-5){
for($ i=$page-4;$i<$page+5;$i++){
$plfront.= "";
}
}else{
for($i=$pagecount-8;$i<=$pagecount;$i++){
} $plfront.= " ".$i."";
}
}
$arr["pagelist"] = $plfront." ";
$arr["nums "] = $num;
}
The above introduces the paging function. It is a useful paging function, including the content of paging functions. I hope it will be helpful to friends who are interested in PHP tutorials.