自己写的非常简单好用的PHP的MYSQL分页类
dbadd=$dbadd; $this->dbuser=$dbuser; $this->dbpwd=$dbpwd; $this->dbname=$dbname; $this->tablename=$tablename; $this->num=$num; $this->total=$this->gettotal(); //得到总条数 $this->totalpage=ceil($this->total/$this->num); //获取总页数 $this->page=$this->getpage(); //得到当前页数 $this->limit=$this->setlimit(); //得到查询的数据 $this->arrs=$this->getarrs(); //得到查询的结果 $this->col=$this->getcol(); //获取总列数 $this->nostart=($this->page-1)*$num+1; $this->noend=$this->page==$this->totalpage ? $this->total : $this->page*$num; $this->head=$this->page==1 ? "首页" : "首页"; $this->end=$this->page==$this->totalpage ? "尾页" : "totalpage}" _href=".html?page={$this->totalpage}">尾页"; $this->last=$this->page==1 ? "上一页" : "page-1)."" _href=".html?page=".($this->page-1)."">上一页"; $this->nexts=$this->page==$this->totalpage ? "下一页" : "page+1)."" _href=".html?page=".($this->page+1)."">下一页"; } private function getcol(){ $linkss=mysql_connect($this->dbadd, $this->dbuser, $this->dbpwd); mysql_select_db($this->dbname, $linkss); $result=mysql_query("select * from {$this->tablename}", $linkss); $col=mysql_num_fields($result); mysql_close($linkss); return $col; } private function getarrs(){ //根据条件再次查询并返回结果 $sql="select * from {$this->tablename} limit {$this->limit}, {$this->num}"; $links=mysql_connect($this->dbadd, $this->dbuser, $this->dbpwd); mysql_select_db($this->dbname, $links); $result=mysql_query($sql, $links); while($arr=mysql_fetch_assoc($result)){ $arrs[]=$arr; } return $arrs; mysql_close($links); } private function setlimit(){ return ($this->page-1)*$this->num; } private function getpage(){ $page=isset($_GET["page"]) ? $_GET["page"] : 1; $page=$page>$this->totalpage ? $this->totalpage : $page; $page=$pagedbadd, $this->dbuser, $this->dbpwd); mysql_select_db($this->dbname, $link); $result=mysql_query("select * from {$this->tablename}", $link); $total=mysql_num_rows($result); mysql_close($link); return $total; } function __get($args){ switch($args){ case "arrs": //根据条件查询出的结果,是二维数组 return $this->arrs; break; case "totalpage": //总页数 return $this->totalpage; break; case "col": //总列数 return $this->col; break; case "page": //当前页 return $this->page; break; case "nostart": //当前页显示的记录的起始条数 return $this->nostart; break; case "noend": //当前页显示的记录的结束条数 return $this->noend; break; case "head": //首页按钮 return $this->head; break; case "end": //尾页按钮 return $this->end; break; case "last": //上一页按钮 return $this->last; break; case "nexts": //下一页按钮 return $this->nexts; break; } } } ?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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
Assassin's Creed Shadows: Seashell Riddle Solution
1 months ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
1 months ago
By DDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks ago
By DDD
InZoi: How To Apply To School And University
3 weeks ago
By DDD

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)
