PHP 分页种
gt
quot
this
PHP 分页类
下面是我自己的分页类,可适当的修改
<?php /** * @name Pager's class * @author Refer * @copyright www.phpcq.com * @version Alpha 1.0 * @todo 下拉菜单分页---From表单传值...可以根据自己的情况(采用GET传值) * */ class Pager{ /** * startRow * * @var Int */ public $startRow; /** * 页面的总数 * * @var Int */ public $pageTotal; /** *翻页值 * * @var Int */ public $offset; /** * 每页所显示记录数 * * @var Int */ public $pageSize; /** * get参数 * * @var Int */ public $get; /** * post参数 * * @var Int */ public $post; /** * 构造函数--初始化翻页类 (PS:^_^不错的php开发学习交流群:256271784,验证:gole,有兴趣的话可以加入进来一起讨论) * * @param Int $total * @param Int $pageSize */ public function __construct($total,$pageSize){ $this->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 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 = "<option>$this->post</option>"; $this->startRow = $this->post; $this->offset = ($this->post - 1) * $this->pageSize; } for ($i = 1; $i pageTotal;$i++){ if ($i != $this->post) { $pageNums .= "<option>$i</option>"; } } 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
登入後複製
模板页面:
<!--{if $pageTotal > 1}-->
登入後複製
本文出自 “清源教育” 博客,转载请注明此处,谢谢!欢迎登录清源教育官网,查看更多视频教程。
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)