本人原創的程式碼,高手看來,也許流程笨拙點,但是很實用.看者要頂啊
/*---------------------------------------- -----------------------//
* 函數說明:分頁函數 page($sql,$pagesize="30")
* $sql 查詢語句(除limit外,可有排序或條件限制)
* 如 select * from stu where time between * 如 select * from stu where time between "1" and "30"; > * ## 可輸出陣列$arr的數值,說明如下:
* $arr["first"] 首頁及位址
*$ arr["all"] 當第幾頁及總頁數
* $arr["page_next"]下一頁及地址
* arr["pagelist"] 頁碼清單及地址,顯示目前頁前後4頁清單
* $arr["query"] 語句 $arr["query"] my_query($$arr[ "nums"] 記錄總數
*
//--------------------------- -------------------------------------*/
function page($sql,$pagesize ="30"){
global $arr,$PHP_SELF;
$query = mysql_query($sql);
$num = my_num_rows($query);
$num = my_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 =LF = $page-1;
$page_url =LF ;
$arr["page_pre"] = "
上一頁|n";
}
if($page $page_next = $page 1;
$page_url = $PHP_SELF . "?page=".$page_next;
.$page_url."">下一頁n";
}
$arr["all"] = "
".$page . "/". $pagecount . "頁n";
$arr["first"] = "
首頁 n|";
$arr["last"] = "|
末頁n";
$plfront="";
if($page=1){
for($i=1;$i $plfront.= "
".$i."";
}
}elseif($page>5 && $page for($i=$page-4;$i $plfront.= "
".$i."";
}
}else{
for($i=$pagecount-8;$i $plfront.= "
".$i."";
>}
$arr["pagelist"] = $plfront." ";
$arr["nums"] = $num;
}
http://www.bkjia.com/PHPjc/316922.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316922.htmlTechArticle複製程式碼如下: 本人原創的程式碼,高手看來,也許流程笨拙看點,但是很實用.者要頂/*-------------------------------------------- ------------------...