$pagnow当前页
$pagecount总页数
if($pagenow>1){
$prepage=$pagenow-1;
echo "<a href='f.php?pagenow=$prepage'>上一页</a>";
}
if($pagenow<$pagecount){
$nexpage=$pagenow+1;
echo "<a href='f.php?pagenow=$nexpage'>下一页</a>";
}
显示当前页和共有多少页
echo "当前页{$pagenow}/共{$pagecount}页";
打印出页码的超链接
方法一:
for($i=1;$i<=$pagecount;$i++){
echo "<a href='f.php?pagenow=$i'>$i</a> ";
}
方法二:
for($j=1;$j<=$pagecount;$j++){
if($currpage == $j){
echo $j.' ';
continue;
}
echo "<a href='?p=$j'>$j</a> ";
}
<a href="?p=1">首页</a>
<a href="?p=<?=$currpage+1?>">下页</a>
<a href="?p=<?php echo $currpage-1;?>">上页</a>
<a href="?p=<?=$pagecount?>">末页</a>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>webrx-php</title>
</head>
<body>
<?php
include 'inc/db_mysqli.php';
$rr = $m->query('select count(*) from member');
$rs = $rr->fetch_row();
$recordcount = $rs[0]; //共13条记录
$pagesize = 1; //每页两条记录
$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>';
}
echo '<hr>';
for($j=1;$j<=$pagecount;$j++){
if($currpage == $j){
echo $j.' ';
continue;
}
echo "<a href='?p=$j'>$j</a> ";
}
?>
<hr>
<a href="?p=1">首页</a>
<a href="?p=<?=$currpage+1?>">下页</a>
<a href="?p=<?php echo $currpage-1;?>">上页</a>
<a href="?p=<?=$pagecount?>">末页</a>
</body>
</html>
百度分页效果的实现
$first=1;
$end=1;
if($currpage>=7){
$first=$currpage-5;
$end=$first+$end-1;
}
if($currpage>1){
$pre=$currpage-1;
echo "<a href='?p=1'>首页</a><a href='?p=$pre'>上一页</a>$nbsp;";
}
if($currpage<$pagecont){
$nex=$currpage+1;
echo "<a href='?p=$nex'>下一页</a><a href='?p=$pagecount'>尾页</a>";
}