<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>分页</title>
<style>
.page{height:30px;padding:15px;clear:both;text-align:center;}
.page a{padding:0px 10px;text-decoration:none;display:inline-block;margin-right:5px;border:solid 1px #c8c7c7;40px;height:35px;line-height:35px;font-size:13px;}
.page a:hover,.page a.checked{text-decoration:none;border:solid 1px #0086d6;background:#0091e3;color:#fff;}
.page a.pages{
font-weight:800;
padding:0px
10px;text-decoration:none;display:inline-block;margin-right:5px;width:40px;height:35px;line-height:35px;font-size:13px;border:none;
}
</style>
</head>
<body>
<?php
include 'mysqli.php';
$rr=$m->query('select count(*) from member');
$rs=$rr->fetch_row();
$recordcount=$rs[0];//共14条记录
$pagesize=1;//每页2条记录
$pagecount=ceil($recordcount/$pagesize);//总共有几页
$currpage=isset($_GET['p']) ? $_GET['p']:1;//显示当前页
$currpage=$currpage<1 ? 1 :$currpage;
$currpage=$currpage>$pagecount ? $pagecount : $currpage;
$start=$currpage*$pagesize-$pagesize;
$r=$m->query("select id,maccount,mname from member limit $start,$pagesize");//里面用变量了所以外面要用单引号
while($rs=$r->fetch_row()){
echo $rs[1].'<br>';
}
$st = 1;
$en = 10;
if($currpage>=6){
$st=$currpage-5;
$en=$st+$en-1;
}
?>
<hr>
<div class="page">
<?php
if($currpage>1){
$pre=$currpage-1;
if($st>1){
echo "<a href='?p=1'>首页</a><a href='?p=$pre'>上一页</a>";
}else{
echo "<a href='?p=$pre'>上一页</a>";
}
}
for($j=$st;$j<=$en;$j++){
if($j>$pagecount){
break;
}
if($currpage==$j){
echo "<a class='pages checked'>$j</a> ";
continue;
}
echo "<a href='?p=$j'>$j</a> ";
} if($currpage<$pagecount){
$nex=$currpage+1;
if($en<$pagecount){
echo "<a href='?p=$nex'>下一页</a><a href='?p=$pagecount'>尾页</a>";
}else{
echo "<a href='?p=$nex'>下一页</a>";
}
}
// echo "当前页{$currpage}/共{$pagecount}页";
?>
</div>
</body>
<html>