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

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

PHP中文网
Release: 2016-05-25 17:13:16
Original
971 people have browsed it

跳至

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;


?>
Copy after login

                   

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template