PHP通用分页种page.php[仿google分页]
PHP通用分页类page.php[仿google分页]
<?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->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 " <font class='".$this->style."'>".$i."</font>"; }else{ return " <a href=".Pager::replacepg($this->url,5,$i)." class='".$this->style."'><u>".$i."</u></a>"; } } //生成上一页等信息的函数 function gotoback($pg){ if ($pg-1>0){ return $this->gotoback=" <a href=".Pager::replacepg($this->url,3,0)." class='".$this->style."'>首页</a> <a href=".Pager::replacepg($this->url,2,0)." class='".$this->style."'>上一页</a>"; }else{ return $this->gotoback="<span class='".$this->style."'>首页 上一页</span> "; } } //生成下一页等信息的函数 function gotonext($pg,$page){ if ($pg < $page){ return " <a href=".Pager::replacepg($this->url,1,0)." class='".$this->style."'>下一页</a> <a href=".Pager::replacepg($this->url,4,0)." class='".$this->style."'>尾页</a>"; }else{ return " <span class='".$this->style."'>下一页 尾页</span>"; } } //处理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; } } ?>
?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

PHP function introduction—get_headers(): Overview of obtaining the response header information of the URL: In PHP development, we often need to obtain the response header information of the web page or remote resource. The PHP function get_headers() can easily obtain the response header information of the target URL and return it in the form of an array. This article will introduce the usage of get_headers() function and provide some related code examples. Usage of get_headers() function: get_header

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

Nowadays, many Windows users who love games have entered the Steam client and can search, download and play any good games. However, many users' profiles may have the exact same name, making it difficult to find a profile or even link a Steam profile to other third-party accounts or join Steam forums to share content. The profile is assigned a unique 17-digit id, which remains the same and cannot be changed by the user at any time, whereas the username or custom URL can. Regardless, some users don't know their Steamid, and it's important to know this. If you don't know how to find your account's Steamid, don't panic. In this article

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Use url to encode and decode the class java.net.URLDecoder.decode(url, decoding format) decoder.decoding method for encoding and decoding. Convert into an ordinary string, URLEncoder.decode(url, encoding format) turns the ordinary string into a string in the specified format packagecom.zixue.springbootmybatis.test;importjava.io.UnsupportedEncodingException;importjava.net.URLDecoder;importjava.net. URLEncoder
