PHP 分頁種

來源:互聯網
上載者:User
PHP 分頁類
下面是我自己的分頁類,可適當的修改
get = (int)$_GET['startRow'];         $this->post = (int)$_POST['pageNums'];         $this->pageSize = $pageSize;         $this->pageTotal = ceil($total / $pageSize);         switch ($_GET['method']){             default:                 $this->startRow = 1;                 $this->offset = 0;             break;             case 'first':                 $this->first();             break;                 case 'previous':                 $this->previous();             break;                 case 'next':                 $this->next();             break;                 case 'last':                 $this->last();             break;             }     }      /**      * 首頁方法      *      */     public function first(){         $this->startRow = 1;         $this->offset = ($this->startRow - 1) * $this->pageSize;    }     /**      * 上一頁方法      *      */     public function previous(){         $this->startRow = $this->get - 1;         if ($this->startRow < 1) {             $this->startRow = 1;         }         $this->offset = ($this->startRow - 1) * $this->pageSize;    }     /**      * 下一頁方法      *      */     public function next(){         $this->startRow = $this->get + 1;         if ($this->startRow > $this->pageTotal) {             $this->startRow = $this->pageTotal;         }         $this->offset = ($this->startRow - 1) * $this->pageSize;    }     /**      * 最後頁方法      *      */     public function last(){         $this->startRow = $this->pageTotal;         $this->offset = ($this->startRow - 1) * $this->pageSize;    }     /**      * 下拉式功能表翻頁      *      * @return Int      */     public function numPages(){         if ($this->post) {             $pageNums = "$this->post";             $this->startRow = $this->post;             $this->offset = ($this->post - 1) * $this->pageSize;        }         for ($i = 1; $i <= $this->pageTotal;$i++){             if ($i != $this->post) {                 $pageNums .= "$i";             }         }         return $pageNums;     }     /**      * 當前是第幾頁      *      * @return Int      */     public function noncePage(){         if ($this->post) {             return $this->startRow = $this->post;         } else {             return $this->startRow = $this->startRow;         }     } } 


調用方法:
$total = $total->total();//總記錄             $pageSize = 15;//每頁顯示的記錄             $pager = new Pager($total,$pageSize);             if ($pager->post){$startRow = $pager->noncePage();}             $startRow = $pager->startRow;             $pager->numPages();             $article->query("SELECT * FROM `categories` as c,`articles` as n WHERE c.id = n.pid                    ORDER BY n.id DESC LIMIT $pager->offset,$pageSize");             while ($article->fetchArray()) {                 $article->data['content'] = mb_substr(strip_tags($article->data['content']),0,40,'utf-8');                 $articleIndex[] = $article->data;                         }             $article->free();         } else {             header("location:?act=login");         }         $view->view->assign('startRow',$startRow);//caption         $view->view->assign('total',$total);//caption         $view->view->assign('pageNums',$pager->numPages());//pageNums         $view->view->assign('noncePage',$pager->noncePage());//pageNums         $view->view->assign('pageTotal',$pager->pageTotal);//pageTotal  


模板頁面:
        

本文出自 “清源教育” 部落格,轉載請註明此處,謝謝!歡迎登入清源教育官網,查看更多視頻教程。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.