php分页类代码与分页调用截图
Lepaskan: 2016-07-25 08:52:36
asal
813 orang telah melayarinya
-
-
class Page {
- private $total; //总记录
- private $pagesize;//每页显示多少条
- private $limit; //limit
- private $page; //当前页码
- private $pagenum; //总页码
- private $url; //地址
- private $bothnum; //两边保持数字分页的量
//构造方法初始化
- public function __construct($_total, $_pagesize) {
- $this->total = $_total ? $_total : 1;
- $this->pagesize = $_pagesize;
- $this->pagenum = ceil($this->total / $this->pagesize);
- $this->page = $this->setPage();
- $this->limit = "LIMIT ".($this->page-1)*$this->pagesize.",$this->pagesize";
- $this->url = $this->setUrl();
- $this->bothnum = 2;
- }
//拦截器
- private function __get($_key) {
- return $this->$_key;
- }
//获取当前页码
- private function setPage() {
- if (!empty($_GET['page'])) {
- if ($_GET['page'] > 0) {
- if ($_GET['page'] > $this->pagenum) {
- return $this->pagenum;
- } else {
- return $_GET['page'];
- }
- } else {
- return 1;
- }
- } else {
- return 1;
- }
- }
//获取地址
- private function setUrl() {
- $_url = $_SERVER["REQUEST_URI"];
- $_par = parse_url($_url);
- if (isset($_par['query'])) {
- parse_str($_par['query'],$_query);
- unset($_query['page']);
- $_url = $_par['path'].'?'.http_build_query($_query);
- }
- return $_url;
- }
//数字目录
- private function pageList() {
- for ($i=$this->bothnum;$i>=1;$i--) {
- $_page = $this->page-$i;
- if ($_page $_pagelist .= ' '.$_page.' ';
- }
- $_pagelist .= ' '.$this->page.' ';
- for ($i=1;$ibothnum;$i++) {
- $_page = $this->page+$i;
- if ($_page > $this->pagenum) break;
- $_pagelist .= ' '.$_page.' ';
- }
- return $_pagelist;
- }
//首页
- private function first() {
- if ($this->page > $this->bothnum+1) {
- return ' 1 ...';
- }
- }
//上一页
- private function prev() {
- if ($this->page == 1) {
- return '上一页';
- }
- return ' 上一页 ';
- }
//下一页
- private function next() {
- if ($this->page == $this->pagenum) {
- return '下一页';
- }
- return ' 下一页 ';
- }
//尾页
- private function last() {
- if ($this->pagenum - $this->page > $this->bothnum) {
- return ' ...'.$this->pagenum.' ';
- }
- }
//分页信息
- public function showpage() {
- $_page .= $this->first();
- $_page .= $this->pageList();
- $_page .= $this->last();
- $_page .= $this->prev();
- $_page .= $this->next();
- return $_page;
- }
- }
- ?>
-
复制代码
2,php分页类调用示例
-
-
$_page = new Page($_total,$_pagesize); //$_total 数据集的总条数,$_pagesize每页显示的数量.
- ?>
复制代码
3,php分页效果截图
|
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
Topik-topik yang berkaitan
Lagi>