在php中分页是我们开发中必须要用到的东西,但在觉得在php分页比在asp中方便了很多,下面我来给各位同学详细介绍人几个不错的php分页类吧,各位同学可参考。
这是我自己写的一个php分页实例
代码如下 | 复制代码 | ||||
//建立连接数据库 $linkID=@mysql_connect("itlobo.com","root","") or die("you could notconnect mysql"); //连接的数据库名称 @mysql_select_db("ceshi") or die("could not select database!"); //取得记录总数 $query="SELECT count(*) FROM user";
} $first = 1; $prev =$page-1; $next = $page+1; $last=$pages; if($page>1) { echo "首页"; echo "上一页"; } if($page { echo "下一页"; echo "最后一页"; } echo " 共有" .$pages. "页(" .$page. "/" .$pages.")"; ";for($i=1; $i echo "[".$i."]"; echo "[" .$page. "]"; for($i=$page+1; $i echo "[".$i."]"; echo" ?> |
上面代码不能重复使用,后来整理了一个类
代码如下 | 复制代码 |
#pages{display:block; text-align:center; overflow:hidden; color:#000; font-size:13px} |
PHP分页函数类源码:
代码如下 | 复制代码 |
/* interface Page{ class AdminPage implements Page{ public function __construct($sql,$p){ $s = new Sql(); } public function showpage(){ if( $this->pageNum $this->pageStr = '
if($this->nowpage!=1){ $this->pageStr .= ' } for($i=1;$ipageNum;$i++){ if($i==$this->nowpage){ $this->pageStr .=' }else{ $this->pageStr .=' } } if($this->nowpage !=$this->pageNum){ $this->pageStr .= ' } $this->pageStr .=' echo $this->pageStr; }else if($this->pageNum>5){ $this->pageStr = ' if($this->nowpage !=1){ $this->pageStr .= ' } for($i=1;$i
if($i==$this->nowpage){ }else{ $this->pageStr .=' } } if($this->nowpage !=$this->pageNum){ $this->pageStr .= ' } $this->pageStr .=' echo $this->pageStr; } }else if($this->nowpage pageNum -2 && $this->nowpage>=5){ $this->pageStr .= ' for($i=$this->nowpage-2;$inowpage+2;$i++){ if($i==$this->nowpage){ $this->pageStr .=' }else{ $this->pageStr .=' } } $this->pageStr .= ' $this->pageStr .=' echo $this->pageStr; }else if($this->nowpage>=$this->pageNum-3 && $this->nowpage pageNum){ $this->pageStr = ' |

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
