PHP分页类
2008-08-23 21:32
197 查看
<?php /** * @author Genshing * @desc 分页处理文件 * @lastmodify 2008-8-23 17:07 * * @param $style:二维数组,存储输出的分页样式。其中: * count:输出当前页码和页码总数,当前页码为NOW,页码总数为COUNT EG: NOW/COUNT 则输出:1/2 * back:上一页,链接处变量为LINK * link:普通页码链接,链接处变量为LINK,页码为PAGE * now:当前页码,页码为PAGE * next:下一页,链接处变量为LINK */ class page { public $count; //记录总数 public $nowpage; //目前页码 public $paginal; //每页记录数 public $pagenum; //页码数量 public $pagecount; //页码总数 public $styletype; //分页风格选择 public $style = array( array( 'count'=>'', 'back'=>'<a class="Arrow" href="LINK" mce_href="LINK"><<</a>', 'link'=>'<a class="SquareLink" href="LINK" mce_href="LINK">PAGE</a>', 'now'=>'<b>PAGE</b>', 'next'=>'<a class="Arrow" href="LINK" mce_href="LINK">>></a>' ), ); //分页风格设置 public function __construct($count, $paginal=20, $pagenum=10, $styletype=0){ $this->count = intval($count); $this->paginal = intval($paginal); $this->styletype = intval($styletype); if(!intval($_GET['page'])){ $this->nowpage = intval($_GET['page']) + 1; } else { $this->nowpage = intval($_GET['page']); } $this->pagenum = intval($pagenum); $this->pagecount = intval($this->count / $this->paginal); if($this->pagecount < 1) $this->pagecount++; if($this->nowpage > $this->pagecount) $this->nowpage = 1; } /** * @author Genshing * @abstract 返回Limit变量 */ public function getlimit(){ $ofset = $this->paginal * ($this->nowpage - 1); return array('limit'=>$this->paginal, 'ofset'=>$ofset); } /** * @author Genshing * @abstract 获取分页输出字符串 * @return Strings */ public function Getlink(){ $getvar = $this->Getvar(); $link = ''; $begin = intval($this->nowpage / $this->pagenum) + 1; if($this->pagecount <= $this->nowpage){ $end = $this->nowpage; } elseif($this->pagecount <= ($begin + $this->pagenum - 1)) { $end = $this->pagecount; } else { $end = $begin + $this->pagenum - 1; } if($this->style[$this->styletype]['count']){ $str = str_replace('NOW',$this->nowpage,$this->style[$this->styletype]['count']); $str = str_replace('COUNT',$this->count,$str); $link .= $str; } if($this->style[$this->styletype]['back']){ $link .= str_replace('LINK','?'.$getvar.'page='.($this->nowpage - 1),$this->style[$this->styletype]['back']); } for ($i = $begin; $i <= $end; $i++){ if($i == $this->nowpage){ if($this->style[$this->styletype]['now']){ $link .= str_replace('PAGE',$i,$this->style[$this->styletype]['now']); } } else { if($this->style[$this->styletype]['link']){ $str = str_replace('LINK','?'.$getvar.'page='.$i,$this->style[$this->styletype]['link']); $str = str_replace('PAGE',$i,$str); $link .= $str; } } } if($this->style[$this->styletype]['next']){ $link .= str_replace('LINK','?'.$getvar.'page='.($this->nowpage + 1),$this->style[$this->styletype]['next']); } //print_r($_GET); return $link; } /** * @author Genshing * @abstract 获取当前GET参数 */ private function Getvar(){ $link = ''; foreach ($_GET as $key=>$tmp){ if($key != 'page') $link .= $key.'='.$tmp.'&'; } return $link; } } ?>
相关文章推荐
- 超级好用的PHP分页类
- Php 分页类
- PHP分页类
- PHP通用分页类page.php[仿google分页]
- ci 分页类 伪静态错误的情况,需要修改\system\libraries\Pagination.php
- php简单分页类
- php 分页类(3)
- php分页类代码 Digg Style Paginator Class
- phpfans留言版用到的数据操作类和分页类
- PHP分页类
- 简单好用的PHP分页类
- php分页类
- php通用分页类代码
- 简单,方便,功能全的php分页类
- php分页类 增强版
- PHP分页类(较完美)
- 一个简单的PHP分页类
- zhphpframework(二十六) php+mysql 分页类
- PHP 分页类及测试代码完整收藏版
- php中的数据库操作类、分页类,以及smarty扩展类