欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP通用分页种page.php[仿google分页]

程序员文章站 2022-06-15 22:04:43
...
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->pagepage+1;$i++){ $this->thestr=$this->thestr.Pager::makepg($i,$this->pg); } }else{ if ($this->pgthestr=$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."页".$this->backstr.$this->thestr.$this->nextstr); } //生成数字分页的辅助函数 function makepg($i,$pg){ if ($i==$pg){ return " ".$i.""; }else{ return " ".$i.""; } } //生成上一页等信息的函数 function gotoback($pg){ if ($pg-1>0){ return $this->gotoback=" 首页 上一页"; }else{ return $this->gotoback="首页 上一页 "; } } //生成下一页等信息的函数 function gotonext($pg,$page){ if ($pg url,1,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; } } ?>

?

PHP通用分页种page.php[仿google分页]

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频