第一,我們先創建一個表,用來存放數據的

本人實現的是用原生php+mysql實現。都混在一起
<?php
header('content-type:text/html;charset=utf-8');
include('./sqldb.php');
$sql="select * from test order by id desc";
$result=mysql_query($sql);
$num=mysql_num_rows($result); //頁總數
$pageSize=5; //頁尺寸
$pageCount=ceil($num/$pageSize); //總頁數
$pageNo=isset($_GET['page'])?$_GET['page']:1; //頁碼
$pageNext=$pageNo+1; //下一頁
$pagePrev=$pageNo-1; //上一頁
//判斷頁碼越界
if($pageNext>$pageCount) $pageNext=$pageCount;
if($pagePrev<1) $pagePrev=1;
if($pageNo>$pageCount) $pageNo=$pageCount;
if($pageNo<1) $pageNo=1;
$offset=($pageNo-1)*$pageSize; //偏移量
mysql_data_seek($result, $offset); //將結果指針移至offset處
?>
<style type="text/css">
tr{background-color:#ffffff; font-size:12px;}
td{text-align:center;height:30px;}
</style>
<table width="100%;" bgcolor="#333666" cellspacing="1">
<tr>
<td>ID</td>
<td>姓名</td>
<td>權限</td>
</tr>
<tr>
<?php
for ($i=0; $i <$pageSize ; $i++):
$row=mysql_fetch_assoc($result);
if ($row) :
?>
<td><?php echo $row['id']?></td>
<td><?php echo $row['name']?></td>
<td>
<?php
switch ($row['flag']) {
case '1':
echo "老師";
break;
case '2':
echo "教授";
break;
default:
echo "學生";
break;
}
?>
</td>
</tr>
<?php
endif;
endfor;
?>
<tr>
<td colspan="3">
共<?php echo $num ?>條
共<?php echo $pageCount ?> 頁
每頁 <?php echo $pageSize ?>條
<a href="Page.class.php?page=1">首頁</a>
<a href="Page.class.php?page=<?php echo $pagePrev ?> ">第一頁</a>
<a href="Page.class.php?page=<?php echo $pageNext?>">下一頁</a>
<a href="Page.class.php?page=<?php echo $pageCount?>">最后一頁</a>
</td>
</tr>
</table>
