<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<meta http
<title>php make page list</title>
<style type="text/CSS">
<!
color: #
text
}
text
color: #
}
text
color: #
}
text
color: #
}
</style>
</head>
<body>
<table width="
<tr>
<th width="
<th width="
</tr>
<?php
/*
* Created on
*
* Order by Kove Wong
*/
$link=MySQL_connect(’localhost’
mysql_select_db(’pagelist’);
mysql_query(’set names gbk’);
$Page_size=
$result=mysql_query(’select * from v_char’);
$count = mysql_num_rows($result);
$page_count = ceil($count/$Page_size);
$init=
$page_len=
$max_p=$page_count;
$pages=$page_count;
//判斷當前頁碼
if(empty($_GET[’page’])||$_GET[’page’]<
$page=
}else {
$page=$_GET[’page’];
}
$offset=$Page_size*($page
$sql="select * from v_char limit $offset
$result=mysql_query($sql
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td bgcolor="#E
<?php echo $row[’id’]?>
</div></td>
<td bgcolor="#E
<?php echo $row[’name’]?>
</div></td>
</tr>
<?php
}
$page_len = ($page_len%
$pageoffset = ($page_len
$key=’<div class="page">’;
$key
if($page!=
$key
$key
}else {
$key
$key
}
if($pages>$page_len){
//如果當前頁小於等於左偏移
if($page<=$pageoffset){
$init=
$max_p = $page_len;
}else{//如果當前頁大於左偏移
//如果當前頁碼右偏移超出最大分頁數
if($page+$pageoffset>=$pages+
$init = $pages
}else{
//左右偏移都存在時的計算
$init = $page
$max_p = $page+$pageoffset;
}
}
}
for($i=$init;$i<=$max_p;$i++){
if($i==$page){
$key
} else {
$key
}
}
if($page!=$pages){
$key
$key
}else {
$key
$key
}
$key
?>
<tr>
<td colspan="
</tr>
</table>
</body>
</html>
From:http://tw.wingwit.com/Article/program/PHP/201311/21036.html