zoukankan      html  css  js  c++  java
  • 分页效果的实现

    $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>";
    }




  • 相关阅读:
    编写第一个 .NET 微服务
    Docker 基础知识编排在开发机上设置和使用 Kubernetes 环境
    将微服务部署到 Azure Kubernetes 服务 (AKS) 实践
    .NET Task.Run vs Task.Factory.StartNew
    Python上下文管理器
    Python可迭代的对象与迭代器的对比
    开发你的第一个SpringBoot应用
    Flask的Blueprints和Views
    Flask项目发布流程
    长篇大论Python生成器
  • 原文地址:https://www.cnblogs.com/lsr111/p/4532181.html
Copyright © 2011-2022 走看看