php实现面向对象的数据分页显示
2017-11-22 10:55
495 查看
一 代码
二 运行结果
大小: 4.9 KB
查看图片附件
<?php class page { private $pagesize; private $page; private $pagecount; private $total; private $conn; public function __construct($pagesize,$page) { $this->pagesize=$pagesize; $this->page=$page; } public function listInfo() { if($this->page=="" || !is_numeric($this->page)) { $this->page=1; } $this->conn=mysql_connect("localhost","root","root"); mysql_select_db("db_database20",$this->conn); mysql_query("set names gb2312"); $sql=mysql_query("select count(*) as total from tb_student",$this->conn); $info=mysql_fetch_array($sql); $this->total=$info[total]; if($this->total==0) { echo "<table width=704 height=20 border=0 align=center cellpadding=0 cellspacing=0>"+ "<tr>"+ "<td><div align=center>暂无学生信息!</div></td>"+ "</tr>"+ "</table>"; } else { if(($this->total % $this->pagesize)==0) { $this->pagecount=intval($this->total/$this->pagesize); } else { if($this->total<=$this->pagesize) { $this->pagecount=1; } else { $this->pagecount=ceil($this->total/$this->pagesize); } } $sql=mysql_query("select * from tb_student order by sno desc limit ".$this->pagesize*($this->page-1).",$this->pagesize",$this->conn); ?> <table width="703" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#476106"> <tr> <td width="100" height="20" bgcolor="#C2C41F"><div align="center">学号</div></td> <td width="100" bgcolor="#C2C41F"><div align="center">姓名</div></td> <td width="100" bgcolor="#C2C41F"><div align="center">性别</div></td> <td width="100" bgcolor="#C2C41F"><div align="center">班级</div></td> <td width="297" bgcolor="#C2C41F"><div align="center">住址</div></td> </tr> <?php while($info=mysql_fetch_array($sql)) { ?> <tr> <td height="20" bgcolor="#FFFFFF"><div align="center"><?php echo $info[sno];?></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><?php echo $info[sname];?></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><?php echo $info[ssex];?></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><?php echo $info[sclass];?></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><?php echo $info[saddress];?></div></td> </tr> <?php } echo "</table>"; } } public function toPage() { ?> <table width="704" height="20" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="342"> 共有学生信息 <?php echo $this->total;?> 条 每页显示 <?php echo $this->pagesize;?> 条 第 <?php echo $this->page;?> 页/共 <?php echo $this->pagecount;?> 页</td> <td width="362"><div align="right"> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=1">首页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php if($this->page>1) echo $this->page-1; else echo 1; ?>">上一页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php if($this->page<$this->pagecount-1) echo $this->page+1; else echo $this->pagecount; ?>">下一页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php echo $this->pagecount;?>">尾页</a> </div></td> </tr> </table> <?php } public function __destruct() { mysql_close($this->conn); } } $obj=new page(4,$_GET["page"]); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>面向对象分页功能</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body topmargin="0" bottommargin="0" leftmargin="0"> <table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/banner.JPG" width="703" height="234"></td> </tr> </table><br> <?php $obj->listInfo(); $obj->toPage(); ?> <table width="704" height="20" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><div align="center">版权所有©吉林省明日科技有限公司 <br>网址:<a href="http://www.mingrisoft.com">http://www.mingrisoft.com</a></div></td> </tr> </table> </body> </html>
二 运行结果
大小: 4.9 KB
查看图片附件
相关文章推荐
- jQuery+Ajax+PHP+Mysql实现分页显示数据
- jQuery+Ajax+PHP+Mysql实现分页显示数据
- jQuery+Ajax+PHP实现异步分页数据显示
- jQuery+Ajax+PHP+Mysql实现分页显示数据实例讲解
- jQuery+Ajax+PHP+Mysql实现分页显示数据
- 基于PHP实现数据分页显示功能
- jQuery+Ajax+PHP+Mysql实现分页显示数据
- 用PHP实现ODBC数据分页显示一例
- 基于PHP实现数据分页显示功能
- 用PHP实现ODBC数据分页显示一例
- jQuery+Ajax+PHP+Mysql实现分页显示数据
- jQuery+Ajax+PHP实现异步分页数据显示--js可参考
- PHP实现数据分页显示的简单实例
- jQuery+Ajax+PHP+Mysql实现分页显示数据
- jq.ajax+php+mysql实现分页显示数据
- jQuery+Ajax+PHP+Mysql实现分页显示数据
- 06-php雇员管理系统-实现显示雇员信息列表分页改进(可以处理大数据100000条)
- php从PostgreSQL 数据库检索数据,实现分页显示以及根据条件查找数据
- jQuery+Ajax+PHP+Mysql实现分页显示数据实例讲解
- jQuery+Ajax+PHP+Mysql实现分页显示数据