Home > php教程 > PHP源码 > Php自用分页函数程序代码

Php自用分页函数程序代码

WBOY
Release: 2016-06-08 17:21:38
Original
957 people have browsed it

一个简单好用的Php自用分页函数,有需要使用分页函数又不想手写的朋友可进入参考。

<script>ec(2);</script>
 代码如下 复制代码
/*
 * 前台分页
 *
 * $page_array = array(
 *  'totle'     =>10,    //总数
 *  'dispage'   =>10,    //每页显示条数
 *  'url'       =>'/article/list/',//url地址
 *  'now_page', =>1, //当前所在页数
 * );
 *
* @return   pagenav
*/
function front_page( $page_array ){
 
    //分页判断
    $lastpage = ceil($page_array['total'] / $page_array['dispage']); //最后一页
    $page_array['now_page'] = min( $lastpage , $page_array['now_page'] );//比较当前页数和最后一页
    $prepage = $page_array['now_page'] - 1;//上一页
    $nextpage = ($page_array['now_page'] == $lastpage ? 0 : $page_array['now_page'] + 1 );//下一页
    $firstcount = ($page_array['now_page']-1) * $page_array['dispage'];
    if( $lastpage  
    //首页
    if($prepage){
        $page_array[]="首页";
    }else{
        $page_array[]="首页";
    }
    //上一页
    if($prepage) {
        $page_array[]=" 上一页 ";
    }else{
        $page_array[]='';
    }
 
    //显示的数字分页条数
    $pagenum=5;
    $offset=2;//偏移两
    $from=$page_array['now_page'] - $offset;//起始
    $to=$page_array['now_page'] + $pagenum-$offset-1;//终止
    if($pagenum>$lastpage){
        $from=1;
        $to=$lastpage;
    }else{
        if($from             $to=$page_array['now_page'] + 1 - $from;
            $from=1;
            if(($to-$from)                 $to=$pagenum;
            }
        }elseif($to>$lastpage){
            $from=$page_array['now_page'] - $lastpage+$to;
            $to=$lastpage;
            if(($to-$from)                 $from=$lastpage-$pagenum+1;
            }
        }
    }
    for($i=$from;$i         if($i == $page_array['now_page']){
            $pagenav.="$i ";
        }else{
            $pagenav.="$i ";
 
        }
    }
    //数字分页
    $page_array[]= $pagenav;
    //下一页
    if($nextpage){
        $page_array[]=" 下一页 ";
    }else {
        $page_array[]='';
    }
    //尾页
    if($nextpage){
        $page_array[]="尾页";
    }else{
        $page_array[]='尾页';
    }
    //记录数
    $page_array[]="每页   ".$page_array['dispage']."  条 共  ".$page_array['total']."  条纪录";
    //分页数
    $page_array[]="共  ".$lastpage." 页";
 
    //跳页
    $page_array[] = '跳转到:
                    Go';
    //第一页总数
    $firstcount=$firstcount     return array('pagenav'=>$page_array,'limit'=>$firstcount,'offset'=> $page_array['dispage'],'allpage'=>$lastpage);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template