PHP自己写的分页

南笙酒味 提交于 2020-02-07 14:27:28
/** * 获奖记录 */public function history(){    $page = max(1,$_GET['page']);//当前页    if(isset($_GET['page_total']) && $page > $_GET['page_total']) $page = $_GET['page_total'];//如果超出页数,就等于最大页数    $offset = ($page - 1) * 10;    $results = $this->score->order('createtime desc')->limit($offset.',10')->select(['user_id'=>$_SESSION['user']['id']],'id,name,score,after,createtime,memo');    //总条数    $page_num = $this->score->count(['user_id'=>$_SESSION['user']['id']]);    //总页数    $page_total = ceil($page_num/10);    include HOME . '/View/draw/history.html';}

HTML代码

<div class="ps-lt">    <div class="lt-dsb b_info" style="text-align: center">        <p>第<?php echo $page?>页/共<?php echo $page_total?>页 <font color="green">            <a href="./index.php?c=draw&a=history&page=<?php echo $page-1;?>">上一页</a>            <?php            if($page < 3){                    $j_start = 1;                    $j_end = $page_total > 4 ? 5 : $page_total;            }else{            $j_start = $page - 2;            $j_end = $page_total-$page >= 2 ? $page+2 : $page_total;            }            ?>            <?php for($j=$j_start;$j<=$j_end;$j++){?>            <a href="./index.php?c=draw&a=history&page=<?php echo $j;?>" <?php if($page == $j) echo 'style="color: red"';?>><?php echo $j;?></a>            <?php }?>            <a href="./index.php?c=draw&a=history&page=<?php echo $page+1?>&page_total=<?php echo $page_total?>">下一页</a></font></p>    </div></div>

效果展示

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!