一直超簡單的php分頁代碼-支援smarty模板分頁

來源:互聯網
上載者:User

<?php
    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 <= 0 ? 1 : $this->page;
           
            $cpage['countPage'] = ceil($this->count/$this->size); //總頁數

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

            //顯示總數
            $cpage['lun'] = $cpage['countPage'] < $this->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");
    */
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.