适用好用的PHP分页类代码与使用
程序员文章站
2024-01-06 19:29:04
...
实用好用的PHP分页类代码与使用
类的代码如下:
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 url.'&page='.$_page.'">'.$_page.' ';??? }??? $_pagelist .= ' '.$this->page.' ';??? for ($i=1;$ibothnum;$i++) {??? ? $_page = $this->page+$i;???? if ($_page > $this->pagenum) break;???? $_pagelist .= ' '.$_page.' ';??? }??? return $_pagelist;?? }???? //首页 http://ini.iteye.com/?? 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;?? }?}?>
??使用说明:
?分页样式如下图所示:?
?
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
上一篇: 用C实现PHP扩展类的步骤_PHP教程
下一篇: 中文编程的奋斗历程
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论