搜尋
首頁php教程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页

                   

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具