php显示页码分页类的封装
发布时间:2021-01-20 11:03:30 所属栏目:编程 来源:网络整理
导读:本文实例为各人分享了php封装表现页码的分页类,供各人参考,详细内容如下 一、代码 conn.php connect(); } public function connect(){ $conn=mysql_pconnect('localhost','root','root') or die("Connect MySQL False"); mysql_select_db('db_database20',
本文实例为各人分享了php封装表现页码的分页类,供各人参考,详细内容如下 一、代码conn.php connect(); } public function connect(){ $conn=mysql_pconnect('localhost','root','root') or die("Connect MySQL False"); mysql_select_db('db_database20',$conn) or die("Connect DB False"); mysql_query("SET NAMES utf8"); } } ?>index.php
page=1;//当前页界说为1
}else{
$this->page=$_GET['page'];//当前页为地点栏参数的值
}
$this->pagesize=$pagesize;
$this->pagelen=$pagelen;
$this->table=$table;
new Mysql();//实例化Mysql类
$sql=mysql_query("select * from $this->table");//查询表中的记录
$this->total=mysql_num_rows($sql);//得到查询的总记录数
$this->pages=ceil($this->total/$this->pagesize);//计较总页数
$this->pageoffset=($this->pagelen-1)/2;//计较页码偏移量
}
function sel(){
$sql=mysql_query("select * from $this->table limit ".($this->page-1)*$this->pagesize.",".$this->pagesize);//查询当前页表现的记录
return $sql;//返回查询功效
}
function myPage(){
$message="第".$this->page."页/共".$this->pages."页";//输出当前第几页,共几页
if($this->page==1){//假如当前页是1
$message.="首页上一页";//输出没有链接的笔墨
}else{
$message.="首页";//输出有链接的笔墨
$message.="page-1)."'>上一页";//输出有链接的笔墨
}
if($this->page<=$this->pageoffset){//假如当前页小于页码的偏移量
$minpage=1;//表现的最小页数为1
$maxpage=$this->pagelen;//表现的最大页数为页码的值
}elseif($this->page>$this->pages-$this->pageoffset){//假如当前页大于总页数减去页码的偏移量
$minpage=$this->pages-$this->pagelen+1;//表现的最小页数为总页数减去页码数再加上1
$maxpage=$this->pages;//表现的最大页数为总页数
}else{
$minpage=$this->page-$this->pageoffset;//表现的最小页数为当前页数减去页码的偏移量
$maxpage=$this->page+$this->pageoffset;//表现的最大页数为当前页数加上页码的偏移量
}
for($i=$minpage;$i<=$maxpage;$i++){//轮回输出数字页码数
if($i==$this->page){
$message.=$i."n";//输出没有链接的数字
}else{
$message.="".$i."n";//输出有链接的数字
}
}
if($this->page==$this->pages){//假如当前页便是最大页数
$message.="下一页尾页";//表现没有链接的笔墨
}else{
$message.="page+1)."'>下一页";//表现有链接的笔墨
$message.="pages."'>尾页";//表现有链接的笔墨
}
return $message;//返回变量的值
}
}
?>
二、运行功效以上就是本文的所有内容,但愿对各人的进修有所辅佐,也但愿各人多多支持编程之家。 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |