<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<style>
a:link{color:#333;text-decoration:none;}
a:visited{color:#333;text-decoration:none;}
a:hover{color:#1b61ff;text-decoration:underline;}
a:active{color:#3B3B3B;}
.page{height:30px;padding:15px 0;clear:both;overflow:hidden;text-align:center;}
.page a{padding:0px 5px;display:inline-block;margin-right:5px;border:solid 1px #c8c7c7;}
.page a:hover,.page a.checked{text-decoration:none;border:solid 1px #0086d6;background:#0091e3;color:#fff;}
</style>
<body>
<?php
$local=‘localhost‘;
$user=‘root‘;
$pass=‘‘;
$dbname=‘oa‘;
$tablename=‘student‘;
$port=3306;
$db=new mysqli($local,$user,$pass,$dbname,$port);
if ($db->connect_error){
die(‘mysql connecting error...‘);
}
$db->set_charset(‘utf8‘);
$stmt=$db->prepare("select count(*) from $tablename");
$stmt->execute();
$stmt->bind_result($zjls);
$stmt->fetch();
$stmt->free_result();
$pagesize=3;
$pagecount=ceil($zjls/$pagesize);
$p=isset( $_GET[‘p‘] )? $_GET[‘p‘] : 1 ;
$stmt=$db->prepare("select * from $tablename limit ?,?");
$start=$p*$pagesize-$pagesize;
$stmt->bind_param(‘ii‘,$start,$pagesize);
$stmt->execute();
$result=$stmt->get_result();
$rows=$result->fetch_all(1);
echo ‘<pre>‘;
print_r($rows);
echo ‘</pre>‘;
echo "<div class=‘page‘>";
$a= 1;
$b= 10;
if($p>=6){
$a=$p-5;
$b=$p+5;
}
if($p>1){
printf("<a href=‘?p=%d‘>上一页</a>",$p-1);
}
if($p>=7){
printf("<a href=‘?p=1‘>首页</a>",$p-1);
}
for($i=$a;$i<=$b;$i++){
if($i>$pagecount) break;
if($i==$p){
printf("<a class=‘checked‘>%d</a>",$i);
continue;
}
printf("<a href=‘?p=%d‘>%d</a>",$i,$i);
}
if($p<=$pagecount-5){
printf("<a href=‘?p=$pagecount‘>末页</a>",$i,$i);
}
if($p<$pagecount){
printf("<a href=‘?p=%d‘>下一页</a>",$p+1);
}
echo ‘</div>‘;
$stmt -> close();
$db->close();
?>
</body>
</html>