Copy CodeThe code is as follows:
My original code, the master seems, perhaps the process clumsy point, but very practical. Look at the top.
/*---------------------------------------------------------------//
* Function Description: Paging function page ($sql, $pagesize = "30")
* $SQL query statement (except limit, can be sorted or conditional)
* such as SELECT * from Stu where time between "1" and "30";
* $pagesize the number of display bars per page
* # # can output the value of the array $arr, described as follows:
* $arr ["First"] home page and address
* $arr ["page_pre"] previous page and address
* $arr ["All"] when pages and total pages
* $arr ["page_next"] next page and address
* $arr ["Last"] end and address
* $arr ["pagelist"] page list and address, display the current page before and after 4 page list
* $arr ["query"] statement $arr ["query"] = mysql_query ($sql)
* $arr ["nums"] Total 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 \ n";
}
$arr ["all"] = "". $page. " /". $pagecount. "Page \ n";
$arr ["First"] = "Home \n|";
$arr ["last"] = "| end \ n";
$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. = "". $i. "";
}
}else{
for ($i = $pagecount-8; $i <= $pagecount; $i + +) {
$plfront. = "". $i. "";
}
}
$arr ["pagelist"] = $plfront. " ";
$arr ["nums"] = $num;
}
The above describes a paging function, a useful paging function, including the content of the paging function, I hope to be interested in PHP tutorial friends helpful.