Home  >  Article  >  php教程  >  PHP 分页类,可以集成到框架内

PHP 分页类,可以集成到框架内

PHP中文网
PHP中文网Original
2016-05-25 17:13:16905browse

跳至

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;$ipage!=$this->pagenum){
			$pagestr.="下一页";
			
		}
		if($this->page+5pagenum){
			$pagestr.="尾页 ";
		}
		return $pagestr;	
	}
	
}
// 测试代码
$page = new page(100,10);
$str=$page->getPage();
echo $str;


?>

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn