PHP面向对象(分页)
<?php
class page
{
var $table;
var $pagesize;
var $totalsize;
var $totalpage;
var $first;
var $page;
var $provepage;
var $nextpage;
function __construct($table,$pagesize)
{
$conn=mysql_connect("localhost","root","123456");
mysql_select_db("baonier");
$this->table=$table;
$this->pagesize=$pagesize;
$sql="select * from ".$this->table."";
$query=mysql_query($sql);
$num=mysql_num_rows($query);
$this->page=isset($_GET['page'])?$_GET['page']:1;
$this->totalsize=$num;
$this->totalpage=ceil(($this->totalsize)/($this->pagesize));
$this->first=($this->pagesize)*($this->page-1);
$this->provepage=$this->page-1;
$this->nextpage=$this->page+1;
}
function get_rows()
{
$sqls="select * from ".$this->table." limit ".$this->first.",".$this->pagesize."";
$querys=mysql_query($sqls);
$dates=Array();
while($rows=mysql_fetch_array($querys))
{
$dates[]=$rows;
}
//print_r($dates);exit;
return $dates;
}
function get_page()
{
if($this->provepage<1){
$this->provepage=1;
}
if($this->nextpage>$this->totalpage){
$this->nextpage=$this->totalpage;
}
$div="<a href=\"?page=1\">首页</a>
<a href=\"?page=$this->provepage\">上一页</a>
<a href=\"?page=$this->nextpage\">下一页</a>
<a href=\"?page=$this->totalpage\">尾页</a>";
return $div;
}
}
?>
<style type="text/css">
.td{ text-align:center;padding-left:20px;padding-right:20px;}
</style>
<html>
<body>
<table style="background-color:#fcc">
<tr>
<td class="td">编号</td>
<td class="td">标题</td>
<td class="td">作者</td>
<td class="td">时间</td>
<td class="td">内容</td>
</tr>
<?php
include "page.php";
$page=new page("news",5);
$arr=$page->get_rows();
foreach ($arr as $rows)
{
?>
<tr style="background-color:#ffc">
<td class="td"><?php echo $rows['nid'] ?></td>
<td class="td"><?php echo $rows['title'] ?></td>
<td class="td"><?php echo $rows['author'] ?></td>
<td class="td"><?php echo $rows['publishtime'] ?></td>
<td class="td"><?php echo $rows['content'] ?></td>
</tr>
<?php
}
?>
</table>
<table>
<tr>
<td style="width:250px;"></td>
<td><?php echo $page->get_page();?></td>
<td style="width:100px;"></td>
</tr>
</table>
</body>
</html>
最新文章
- Linux下Java开发环境搭建—CentOS下Eclipse的安装教程
- SQL 存储和触发器
- 使用buildbot实现持续集成(转载)
- 缺少HTML Doctype造成的样式问题
- css javascript 自动化压缩(保存后即自动生成压缩文件)
- Windows Server 2008 网管数据采集 努力做“日拱一卒“
- Winform: use the WebBrowser to display XML with xslt, xml, xslt 转 html 字符串
- Maven配置插件跳过测试代码的编译和运行
- 2、Web应用程序中的安全向量 -- CSRF/XSRF(跨站请求伪造)
- python爬虫xpath
- sublimeserver启动本地服务器(sublime text)
- android cookie持久化
- 4.2 Oracle Dataguard failover 操作步骤
- 【练习】Python第四次:实现对文件的增删改查
- mvc Model验证总结及常用正则表达式
- [2011山东ACM省赛] Mathman Bank(模拟题)
- java实现读取ftp服务器上的csv文件
- Servlet 3.0 对异步处理的支持
- 145.Binary Tree Postorder Traversal---二叉树后序非递归遍历
- Linux安装apue.3e(基于ubuntu16.0.4)