-
-
//php分页类代码
- class page{
- public $page; //当前页
- public $pagenum; // 页数
- public $pagesize; // 每页显示条数
- public function __construct($count, $pagesize){
- $this->pagenum = ceil($count/$pagesize);
- $this->pagesize = $pagesize;
- $this->page =(isset($_GET['p'])&&$_GET['p']>0) ? intval($_GET['p']) : 1;
- }
- /**
- * 获得 url 后面get传递的参数
- */
- public function getUrl(){
- $url = 'index.php?'.http_build_query($_GET);
- $url = preg_replace('/[?,&]p=(\w)+/','',$url);
- $url .= (strpos($url,"?") === false) ? '?' : '&';
- return $url;
- }
- /**
- * 获得分页html
- */
- public function getPage(){
- $url = $this->getUrl();
- $start = $this->page-5;
- $start=$start>0 ? $start : 1;
- $end = $start+9;
- $end = $endpagenum ? $end : $this->pagenum;
- $pagestr = '';
- if($this->page>5){
- $pagestr = "首页 ";
- }
- if($this->page!=1){
- $pagestr.= "上一页";
- }
-
- for($i=$start;$i $pagestr.= "".$i." ";
- }
- if($this->page!=$this->pagenum){
- $pagestr.="下一页";
-
- }
- if($this->page+5pagenum){
- $pagestr.="尾页 ";
- }
- return $pagestr;
- } // edit: bbs.it-home.org
-
- }
- // 分页代码测试
- $page = new page(100,10);
- $str=$page->getPage();
- echo $str;
- ?>
复制代码
|