<?php
require_once('./page.class.php'); //分页类
$showrow = 3;//一页显示的行数
$curpage = empty($_GET['page'])?1:$_GET['page'];//当前的页,还应该处理非数字的情况
$url = "?page={page}";//分页地址,如果有检索条件 ="?page={page}&q=".$_GET['q']
//省略了链接mysql的代码,测试时自行添加
$sql = "SELECT * FROM table";
$query = mysql_query($sql);
$total = mysql_num_rows($query);//记录总条数
if(!empty($_GET['page']) && $total !=0 && $curpage > ceil($total/$showrow))
$curpage = ceil($total_rows/$showrow);//当前页数大于最后页数,取最后一页
//获取数据
$get_data = "select * from table limit ".($curpage-1)*$showrow.",$showrow;";
...
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>简易通用的PHP分页类-www.jb200.com</title>
<style type="text/css">
#page{
height:40px;
padding:20px 0px;
}
#page a{
display:block;
float:left;
margin-right:10px;
padding:2px 12px;
height:24px;
border:1px #cccccc solid;
background:#fff;
text-decoration:none;
color:#808080;
font-size:12px;
line-height:24px;
}
#page a:hover{
color:#077ee3;
border:1px #077ee3 solid;
}
#page a.cur{
border:none;
background:#077ee3;
color:#fff;
}
#page p{
float:left;
padding:2px 12px;
font-size:12px;
height:24px;
line-height:24px;
color:#bbb;
border:1px #ccc solid;
background:#fcfcfc;
margin-right:8px;
}
#page p.pageRemark{
border-style:none;
background:none;
margin-right:0px;
padding:4px 0px;
color:#666;
}
#page p.pageRemark b{
color:red;
}
#page p.pageEllipsis{
border-style:none;
background:none;
padding:4px 0px;
color:#808080;
}
</style>
</head>
<body>
<div class="main">
<div class="showData">
<!--显示数据区-->
</div>
<div class="showPage">
<?php
if($total>$showrow){//总记录数大于每页显示数,显示分页
$page = new page($total,$showrow,$curpage,$url,2);
echo $page->myde_write();
}
?>
</div>
</div>
</body>
</html>