分页效果的实现

Posted on 2015-05-27 00:13  小蕊同学  阅读(223)  评论(0编辑  收藏  举报
$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>&nbsp";
}
方法二:
for($j=1;$j<=$pagecount;$j++){
if($currpage == $j){
   echo $j.'&nbsp;';
continue;
}
    echo "<a href='?p=$j'>$j</a>&nbsp;";
}
<a href="?p=1">首页</a>
<a href="?p=<?=$currpage+1?>">下页</a>
<a href="?p=<?php echo $currpage-1;?>">上页</a>
<a href="?p=<?=$pagecount?>">末页</a>
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>webrx-php</title>
  6. </head>
  7. <body>
  8. <?php
  9. include 'inc/db_mysqli.php';
  10. $rr = $m->query('select count(*) from member');
  11. $rs = $rr->fetch_row();
  12. $recordcount = $rs[0]; //共13条记录
  13. $pagesize = 1; //每页两条记录
  14. $pagecount = ceil($recordcount/$pagesize); //总页数
  15. $currpage = isset($_GET['p']) ? $_GET['p'] : 1;//当前页
  16. $currpage = $currpage<=1 ? 1 : $currpage;
  17. $currpage = $currpage>=$pagecount ? $pagecount : $currpage;
  18. $start = $currpage*$pagesize-$pagesize;
  19. $r = $m->query("select id,maccount,mname from member limit $start,$pagesize");
  20. while($rs = $r->fetch_row()){
  21. echo $rs[1].'<br>';
  22. }
  23. echo '<hr>';
  24. for($j=1;$j<=$pagecount;$j++){
  25. if($currpage == $j){
  26. echo $j.'&nbsp;';
  27. continue;
  28. }
  29. echo "<a href='?p=$j'>$j</a>&nbsp;";
  30. }
  31. ?>
  32. <hr>
  33. <a href="?p=1">首页</a>
  34. <a href="?p=<?=$currpage+1?>">下页</a>
  35. <a href="?p=<?php echo $currpage-1;?>">上页</a>
  36. <a href="?p=<?=$pagecount?>">末页</a>
  37. </body>
  38. </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>";
}




Copyright © 2024 小蕊同学
Powered by .NET 9.0 on Kubernetes