一款php分页代码
时间:2014-06-09 16:40来源: 作者: 点击:
次
以前写过很多php 分页类但是今天这款分页程序我感觉是很好的,简洁实用,代码合理并没有多余的代码,是一款不错分页类函数哦。 class multipage{ var $total ; var $perpage ; var $pages ; var $maxpage ; v
以前写过很多php 分页类但是今天这款分页程序我感觉是很好的,简洁实用,代码合理并没有多余的代码,是一款不错分页类函数哦。
- class multipage {
- var $total;
- var $perpage;
- var $pages;
- var $maxpage;
- var $offset = 9;
- var $curr_page;
-
- function init($total, $perpage, $maxpage) {
- $this->total;
- $this->perpage;
- $this->maxpage;
- $this->offset = 9;
- }
-
- function getpagelist() {
- $result_pages = "";
- $this->pages = ceil($this->total / $this->perpage);
-
- if ($this->pages > $this->maxpage) {
- $from = $this->curr_page - $this->offset;
- if ($from < 1) {
- $from = 1;
- }
- $to = $from + $this->maxpage - 1;
- if ($to > $this->pages) {
- $to = $this->pages;
- if (($to - $from) < $this->maxpage) {
- $from = $from - 1;
- }
- }
- } else {
- $from = 1;
- $to = $this->pages;
- }
-
- $p = 0;
- for($i = $from; $i <= $to; $i++) {
- $result_pages[$p] = $i;
- $p++;
- }
-
- return $result_pages;
- }
-
- function getfirst() {
- if ($this->curr_page > 1 && $this->pages > 1) {
- return 1;
- } else {
- return "";
- }
- }
-
- function getlast() {
- if ($this->pages > 1 && $this->curr_page < $this->pages) {
- return $this->pages;
- } else {
- return "";
- }
- }
-
- function getprev() {
- $prevpage = $this->curr_page - 1;
- if ($prevpage > 0) {
- return $prevpage;
- } else {
- $prevpage = "";
- return $prevpage;
- }
- }
-
- function getnext() {
- $nextpage = $this->curr_page + 1;
- if ($nextpage <= $this->pages) {
- return $nextpage;
- } else {
- $nextpage = "";
- return $nextpage;
- }
- }
-
- function gettotal() {
- if ($this->pages > 0) {
- return $this->pages;
- } else {
- return 1;
- }
- }
-
- }
-
- $page = new multipage();
- $page->gettotal();
- $page->getnext();
(责任编辑:admin) |
------分隔线----------------------------