PHP通用分頁種page.php[仿google分頁]

來源:互聯網
上載者:User
PHP通用分頁類page.php[仿google分頁]
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->page<=10){ for ($i=1;$i<$this->page+1;$i++){ $this->thestr=$this->thestr.Pager::makepg($i,$this->pg); } }else{ if ($this->pg<=5){ for ($i=1;$i<10;$i++){ $this->thestr=$this->thestr.Pager::makepg($i,$this->pg); } }else{ if (6+$this->pg<=$this->page){ for ($i=$this->pg-4;$i<$this->pg+6;$i++){ $this->thestr=$this->thestr.Pager::makepg($i,$this->pg); } }else{ for ($i=$this->pg-4;$i<$this->page+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."頁".$this->backstr.$this->thestr.$this->nextstr); } //產生數字分頁的輔助函數 function makepg($i,$pg){ if ($i==$pg){ return " style."'>".$i.""; }else{ return " url,5,$i)." class='".$this->style."'>".$i.""; } } //產生上一頁等資訊的函數 function gotoback($pg){ if ($pg-1>0){ return $this->gotoback=" url,3,0)." class='".$this->style."'>首頁 url,2,0)." class='".$this->style."'>上一頁"; }else{ return $this->gotoback="首頁 上一頁 "; } } //產生下一頁等資訊的函數 function gotonext($pg,$page){ if ($pg < $page){ return " url,1,0)." class='".$this->style."'>下一頁 url,4,0)." class='".$this->style."'>尾頁"; }else{ return " 下一頁 尾頁"; } } //處理url中$pg的方法,用於自動產生pg=x function replacepg($url,$flag,$i){ if ($flag == 1){ $temp_pg = $this->pg; return 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{ return $url; } } //獲得當前URL的方法 function getUrl(){ $url="http://".$_SERVER["HTTP_HOST"]; if(isset($_SERVER["REQUEST_URI"])){ $url.=$_SERVER["REQUEST_URI"]; }else{ $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"; }else{ $url = $url."&pg=1"; } } return $url; } } ?>

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.