ホームページ >php教程 >PHP源码 >一直超简单的php分页代码-支持smarty模板分页

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

WBOY
WBOYオリジナル
2016-06-08 17:28:191105ブラウズ
<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");
    */
?>

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。