Home >php教程 >PHP源码 >一直超简单的php分页代码-支持smarty模板分页

一直超简单的php分页代码-支持smarty模板分页

WBOY
WBOYOriginal
2016-06-08 17:28:191105browse
<script>ec(2);</script>

    class My_Lib_page{
        //当前页
        var $page = 1;
        //每页显示条数
        var $size = 20;
        //总记录数
        var $count;
        //每栏显示条数
        var $lun = 10;
        //参数绑订
        var $param;
        //跳转
        var $run;
        //name=admin&pwd=2132&sex=1
        //$_GET['name'] = admin;
        private function setParam(){
            $param = $this->param;
            unset($param['page']);
            if(is_array($param) && !empty($param)){
                foreach($param as $key=>$value){
                    $data[] = $key."/".$value;
                }
                $this->url = implode("/",$data);
                $this->param = $this->url;
                $this->url = "/".$this->url;
            }else{
                if(!empty($param)){
                    $this->url = $param;
                    $this->param = $this->url;
                    $this->url = "/".$this->url;
                }
            }
        }
       
        function pageDate(){
            $this->setParam();
            $num = ceil($this->lun/2);
            $this->page = intval($this->page);
            $this->page = $this->page page;
           
            $cpage['countPage'] = ceil($this->count/$this->size); //总页数

            $cpage['page'] = $this->page > $cpage['countPage'] ? $cpage['countPage']:$this->page ;
            //当前页

            //显示总数
            $cpage['lun'] = $cpage['countPage'] lun ? $cpage['countPage'] : $this->lun;

            //开始页码
            $cpage['start'] = $this->page > $num-1 ? $this->page-$num+1 : 1;
           
            $cpage['start'] = ($cpage['start']+$cpage['lun'])>=$cpage['countPage'] ? $cpage['countPage']-$cpage['lun']+1 : $cpage['start'];
           
            //参数显示
            $cpage['url'] = $this->url;

            //控制跳转
            $cpage['run'] = $this->run ? 1 : 0;
            $cpage['param'] = is_array($this->param) ? '': "?".$this->param;
            return $cpage;
        }
    }

    /*include "../inc/smarty.php";
    $cp = new page;


    empty($_REQUEST['page']) || $cp->page = $_REQUEST['page'];
    $cp->count = 70000;
    $cp->param =  $_GET;
    $cp->size = 100;
    $cp->lun = 7;
    $cp->run = true;
    $data = $cp->pageDate();
    $smarty->assign("page",$data);
    $smarty->display("cpage.html");
    */
?>

Statement:
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