• php 经典分页(推荐和laypage配合)


    学习地址:http://www.imooc.com/video/2463

    <?php 
    //(ps:推荐使用laypage整站式跳转来渲染分页按钮样式比较舒服http://laypage.layui.com/,还可以开启内置样式和跳页等功能很不错哦~)
    //require_once '../include.php';
    //$sql="select * from imooc_admin";
    //$totalRows=getResultNum($sql);
    ////echo $totalRows;
    //$pageSize=2;
    ////得到总页码数
    //$totalPage=ceil($totalRows/$pageSize);
    //$page=$_REQUEST['page']?(int)$_REQUEST['page']:1;
    //if($page<1||$page==null||!is_numeric($page)){
    //    $page=1;
    //}
    //if($page>=$totalPage)$page=$totalPage;
    //$offset=($page-1)*$pageSize;
    //$sql="select * from imooc_admin limit {$offset},{$pageSize}";
    ////echo $sql;
    //$rows=fetchAll($sql);
    ////print_r($rows);
    //foreach($rows as $row){
    //    echo "编号:".$row['id'],"<br/>";
    //    echo "管理员的名称:".$row['username'],"<hr/>";
    //}
    //echo showPage($page,$totalPage);
    //echo "<hr/>";
    //echo showPage($page,$totalPage,"cid=5&pid=6");
    function showPage($page,$totalPage,$where=null,$sep="&nbsp;"){
        $where=($where==null)?null:"&".$where;
        $url = $_SERVER ['PHP_SELF'];
        $index = ($page == 1) ? "首页" : "<a href='{$url}?page=1{$where}'>首页</a>";
        $last = ($page == $totalPage) ? "尾页" : "<a href='{$url}?page={$totalPage}{$where}'>尾页</a>";
        $prevPage=($page>=1)?$page-1:1;
        $nextPage=($Page>=$totalPage)?$totalPage:$page+1;
        $prev = ($page == 1) ? "上一页" : "<a href='{$url}?page={$prevPage}{$where}'>上一页</a>";
        $next = ($page == $totalPage) ? "下一页" : "<a href='{$url}?page={$nextPage}{$where}'>下一页</a>";
        $str = "总共{$totalPage}页/当前是第{$page}页";
        for($i = 1; $i <= $totalPage; $i ++) {
            //当前页无连接
            if ($page == $i) {
                $p .= "[{$i}]";
            } else {
                $p .= "<a href='{$url}?page={$i}{$where}'>[{$i}]</a>";
            }
        }
         $pageStr=$str.$sep . $index .$sep. $prev.$sep . $p.$sep . $next.$sep . $last;
         return $pageStr;
    }
  • 相关阅读:
    贪心 CodeForces 137B Permutation
    贪心 CodeForces 124B Permutations
    数学 SCU 4436 Easy Math
    模拟+贪心 SCU 4445 Right turn
    ACM配置指南
    ACM牛人博客
    ✅问题:Rails.ajax自定义请求
    Jbuilder(3300✨)
    关于keyCode, 键盘代码。 和零散的javascript知识。http://js2.coffee/(转化工具)
    ✅javascript 语法:附加子节点
  • 原文地址:https://www.cnblogs.com/CyLee/p/5725510.html
Copyright © 2020-2023  润新知