首頁  >  文章  >  後端開發  >  google chrome瀏覽器下載 PHP通用分頁類pagephp[仿google分頁]

google chrome瀏覽器下載 PHP通用分頁類pagephp[仿google分頁]

WBOY
WBOY原創
2016-07-29 08:38:441195瀏覽

page.php

複製程式碼 程式碼如下:


/**
** 通用php分頁類別。 (仿Google樣式)
** 只需提供記錄總數與每頁顯示數兩個參數。 (已附詳細使用說明..)
** 無需指定URL,連結由程式產生。方便用於檢索結果分頁。
** 表單採用GET方法提交,可保證在諸如查詢之,刪除之類的操作時,不丟失URL參數
**/
class Pager{
//IE網址列位址
var $url;
//記錄總條數
var $countall;
//總頁數
var $page;
//分頁數字連結
var $thestr;
//首頁、上一頁連結
var $backstr;
//尾頁、下一頁連結
var $nextstr;
//目前頁碼
var $pg;
//每頁顯示記錄數
var $countlist;
//翻頁樣式
var $style;
//建構函數,實例化該類別的時候自動執行該函數
function Pager($countall,$countlist ,$style="page"){
//記錄數與每頁顯示數不能整隊時,頁數取餘後加1
$this->countall = $countall;
$this- >countlist = $countlist;
$this->style=$style;
if ($this->countall%$this->countlist!=0){
$this->page=sprintf( "%d",$this->countall/$this->countlist)+1;
}else{
$this->page=$this->countall/$this->countlist;
}
$this->pg=$_GET["pg"];
//保證pg在未指定的情況下為從第1頁開始
if (!ereg("^[1- 9][0-9]*$",$this->pg) || empty($this->pg)){
$this->pg=1;
}
//頁碼超出最大範圍,取最大值
if ($this->pg>$this->page){
$this->pg=$this->page;
}
//得到目前的URL。具體實作請看最底部的函式實體
$this->url = Pager::getUrl();
//取代錯誤格式的頁碼為正確頁碼
if(isset($_GET["pg "]) && $_GET["pg"]!=$this->pg){
$this->url=str_replace("?pg=".$_GET["pg"],"?pg=$ this->pg",$this->url);
$this->url=str_replace("&pg=".$_GET["pg"],"&pg=$this->pg",$this- >url);
}
//產生12345等數字形式的分頁。
if ($this->pagefor ($i=1;$ipage+1;$i++){
$this->; thestr=$this->thestr.Pager::makepg($i,$this->pg);
}
}else{
if ($this->pgfor ($i=1;$i$this - >thestr=$this->thestr.Pager::makepg($i,$this->pg);
}
}else{
if (6+$this->pgpage){
for ($i=$this->pg-4; $ipg+6;$i++){
$this->thestr=$this->thestr.Pager::makepg($i,$this->pg);
}
}else{
for ($i=$this->pg-4;$ipage+1;$i++){
$this-> ;thestr =$this->thestr.Pager::makepg($i,$this->pg);
}
}
}
}
//產生上一頁下頁等文字連結
$this->backstr = Pager::gotoback($this->pg ) ;
$this->nextstr = Pager::gotonext($this->pg,$this->page);
//echo ("共".$this->countall."條, 每頁".$this->countlist."條,共".$this->page."頁".$這->backstr.$this->thestr.$this->nextstr);
}
//產生數字分頁的輔助函數
function makepg($i,$pg){
if ($i==$pg){
return " style."' >".$i."
}else{
return " 樣式。" '>".$i."";
}
}
//產生上一頁等資訊的函數
function gotoback($pg ){
if ($pg-1>0){
回傳$this ->gotoback=" style."'>首頁 style."'>上一頁";
}else{
return $this->gotoback="style."'>首頁上一頁 "
}
}
//產生下一頁等資訊的函數
function gotonext($pg,$page){
if ($pg return " style."'>下一頁 url,4,0).".$this->style."'>尾頁";
}else {
return " style."'>下一頁尾頁";
}
}
//處理url中$pg的方法,用於自動產生pg=x
function Replacepg($url,$flag,$i){
if ($mark == 1){
$temp_pg = $this-> pg;
回傳str_replace("pg=".$temp_pg,"pg=".($this->pg+1),$url)
}else if($flag == 2) {
$temp_pg = $this->pg
return str_replace("pg=".$temp_pg,"pg=".($this->pg-1),$url)
}else if ($flag == 3) {
$temp_pg = $this->pg;
return str_replace("pg=".$temp_pg,"pg=1",$url)
}else if ($flag = = 4){
$temp_pg = $this->pg
return str_replace("pg=".$temp_pg,"pg=".$this->page,$url); 🎜>}else if( $flag == 5){
$temp_pg = $this->pg;
return str_replace("pg=".$temp_pg,"pg=".$i,$url) ;
}else {
回傳$url
}
}
//取得目前URL的方法
function getUrl(){
$url="http:///".$_SERVER[ "HTTP_HOST"];
if(isset($_SERVER["REQUEST_URI"])){
$url.=$_SERVER["REQUEST_URI"];
}其他{
$url.= $_SERVER["PHP_SELF"]
if(!empty($_SERVER["QUERY_STRING"])){
$url.="?".$_SERVER["QUERY_STRING"]; ;
}
}
//在目前的URL裡加入pg=x字樣
if (!ereg("(pg=|PG=|pG=|Pg=)", $url ) ){
if (!strpos($url,"?")){
$url = $url."?pg=1";
}其他{
$url = $url."&pg=1";
}
}
回傳 $url;
}
}
?>

以上就介紹了google chrome瀏覽器下載 PHP通用分頁類pagephp[仿google分頁],包含了google chrome瀏覽器下載方面的內容,希望對PHP教學有興趣的朋友得到幫助。

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