search
Homephp教程PHP源码PHP分页类,支持自定义样式,中间5页

           

<?php

//namespace Component;
/**
 * 2016-3-27
 * @author ankang
 */
class Page {
	private $ShowPage;
	private $CountPage;
	private $Floorp;
	private $PageUrl;
	private $PageClass;
	private $CurClass;
	
	/**
	 * @author ankang
	 * @param number $CountNum        	数据总数
	 * @param string $PageUrl        	跳转链接
	 * @param string $PageClass       	标签 总体样式	
	 * @param string $PageUrl        	当前页样式
	 * @param number $PageSize        	每页显示的数据条数
	 * @param number $ShowPage        	每次显示的页数	
	 */
	public function __construct($CountNum, $PageUrl = NULL, $PageClass = NULL,$CurClass = NULL, $PageSize = 20, $ShowPage = 5) {
		$this->ShowPage 		= $ShowPage;
		$this->CountPage 		= ceil ( $CountNum / $PageSize );
		$this->Floorp 			= floor ( $ShowPage / 2 ); // 偏移量		
		$this->PageClass 		= is_null ( $PageClass ) ? &#39;&#39; : $PageClass;
		$this->CurClass 		= is_null ( $CurClass ) ? &#39;&#39; : $CurClass;
		
		// $ServerURL		        = ( preg_match(&#39;/\?/i&#39;, $_SERVER[&#39;REQUEST_URI&#39;]))?preg_replace(&#39;/\&p\=[0-9]+/i&#39;, "", $_SERVER[&#39;REQUEST_URI&#39;]) : $_SERVER[&#39;REQUEST_URI&#39;]."?";
		// if( substr($ButURL,0,2)==&#39;//&#39; ){
			// $ServerURL          = substr($ServerURL,1);
		// }
		// $url                	= preg_replace(&#39;/p=[\d]*/i&#39;, &#39;&#39;, $ServerURL);
		   $url					= &#39;&#39;;
		//推荐自己传url,不传也可以打开上面的代码自动获取
		$this->PageUrl 			= is_null ( $PageUrl ) ? $url : $PageUrl;
	}
	
	/**
	 *
	 * @param number $Page        	
	 * @param string $ShowToPage
	 *        	首页,上下页,尾页
	 * @param string $Html	标签元素,li,p      
	 * @return string
	 */
	public function getPage($Page = 1, $ShowToPage = true, $Html = null) {
		$StartPage 			= ($Page - $this->Floorp); // 开始页码
		$EndPage 			= ($Page + $this->Floorp); // 结束页码
		
		if ($this->CountPage < $this->ShowPage) {
			$StartPage 		= 1;
			$EndPage 		= $this->CountPage;
		}
		
		if ($StartPage < 1) {
			$StartPage 		= 1;
			$EndPage 		= $this->ShowPage;
		}
		
		if ($EndPage > $this->CountPage) {
			$StartPage 		= $this->CountPage - $this->ShowPage + 1;
			$EndPage 		= $this->CountPage;
		}
		
		$PageHtml = &#39;&#39;;
		
		if (! is_null ( $Html )) {
			if ($Html == &#39;li&#39;) {
				$Shtml = &#39;&#39;;
				$Ehtml = &#39;&#39;;
			} else {
				$Shtml = &#39;&#39;;
				$Ehtml = &#39;&#39;;
			}
		}
		
		if (true == $ShowToPage) {
			$PageHtml 				.= "$ShtmlPageUrl}p=1.html" _href="{$this->PageUrl}p=1.html">&laquo; 首页$Ehtml";
			$PrveUrl				 = $this->getPrve($Page);
			$PageHtml 				.= "$Shtml&laquo; 上一页$Ehtml";
		}
		
		for($i = $StartPage; $i getNext($Page);
			$PageHtml 				.= "$Shtml下一页 &raquo;$Ehtml";
			$PageHtml 				.= "$ShtmlPageUrl}p={$this->CountPage}.html" _href="{$this->PageUrl}p={$this->CountPage}.html">尾页 &raquo;$Ehtml";
		}
		
		return $PageHtml;
	}
	
	public function getPrve($Page){
		if ($Page != 1) {
			$Prve 				 = $Page - 1;
			$PrveUrl 			 = "{$this->PageUrl}p={$Prve}";
		} else {
			$PrveUrl 			 = "{$this->PageUrl}p=1";
		}
		
		return $PrveUrl;
	}
	
	public function getNext($Page){
		if ($Page != $this->CountPage) {
			$Next 				 = $Page + 1;
			$NextUrl 			 = "{$this->PageUrl}p={$Next}";
		} else {
			$NextUrl 			 = "{$this->PageUrl}p={$this->CountPage}";
		}
		
		return $NextUrl;
	}
	
	
	
}

                                       

           

2. [图片] page.pngPHP分页类,支持自定义样式,中间5页    

PHP分页类,支持自定义样式,中间5页

                   

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function