<?php
$con=mysqli_connect('localhost','root','','stu');
mysqli_query($con,"set names utf8"); //設置字符集為utf8
$sql="select * from teacher";
$result=mysqli_query($con,$sql);
$count=mysqli_num_rows($result); //記錄總條數$count。
$pagesize=10;//每頁要顯示的記錄條數$pagesize
if ($count%$pagesize==0) $pagecount=$count/$pagesize;else $pagecount=(int)($count/$pagesize+1); //總頁數$pagecount
$row=mysqli_fetch_assoc($result); //數組$row的鍵名為字段名
??
$page=@$_REQUEST["page"]; ?//欲顯示的頁數$page
if ($page==null) $currentpage=1;else $currentpage=intval($page);
for($i=1;$i<=($currentpage-1)*$pagesize;$i++) //指定每一頁面顯示20條記錄?
{ ?if (!$row) break;
? ?$row=mysqli_fetch_assoc($result);?
}
?>
<table width="500" border="1" align="center" cellpadding="0">
? <tr>
? ? <td height="25" colspan="5" align="center" bgcolor="#99CCCC">第<?php echo $currentpage;?>頁/共<?php echo $pagecount;?>頁</font>
?? ? <?php
?? ? ?if ($currentpage==1) ?echo "首 頁 | 上一頁 | ";
?? ? ?else
? ? ? {?>
?? ??? ? ?<a href="EX7-7.php?page=1">首 頁</a> |
?? ??? ? ?<a href="EX7-7.php?page=<?php echo $currentpage-1;?>">上一頁</a> |
?? ? ?<?php
?? ? ?}
?? ??? ? ??? ?
?? ? ?if ($currentpage==$pagecount) echo "下一頁 | 尾 頁";
?? ? ?else
?? ? ?{?>
?? ??? ? ?<a href="EX7-7.php?page=<?php echo $currentpage+1;?>">下一頁</a> |
?? ??? ? ?<a href="EX7-7.php?page=<?php echo $pagecount;?>">尾 頁</a>
?? ? ?<?php
?? ? ?}
?? ? ??></td>
? </tr>
? <tr>
? ? <td width="100" height="25" align="center">職工號</td>
? ? <td width="100" height="25" align="center">姓名</td>
? ? <td width="100" height="25" align="center">密碼</td>
? ? <td width="100" height="25" align="center">性別</td>
? ? <td width="100" height="25" align="center">出生日期</td>
? </tr>
? ?<?php
?? ??? ?for($i=1;$i<=$pagesize;$i++)
?? ??? ?{ ?if (!$row) break;?? ??? ?
? ??> ? ? ? ?
? <tr>
? ? <td width="100" height="25" align="center"><?php echo $row["職工號"];?></td>
? ? <td width="100" height="25" align="center"><?php echo $row["姓名"];?></td>
? ? <td width="100" height="25" align="center"><?php echo $row["密碼"];?></td>
? ? <td width="100" height="25" align="center"><?php echo $row["性別"];?></td>
? ? <td width="100" height="25" align="center"><?php echo $row["出生日期"];?></td>
? </tr>
? ?<?php
?? ??? ? ? ?$row=mysqli_fetch_assoc($result);?
?? ??? ?}
?? ??>
</table>
添加teacher表中的數據
首先創建表中的表頭內容
在填入數據
最后的結果如下圖: