分页
导入page包,调用相应的方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ">
<html xmlns=" ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>区域名称</td>
<td>父级代号</td>
</tr>
<?php
include ("DBDA.class.php");
$db = new DBDA();
include("Page.class.php");
//求总条数
$szong = "select count(*) from ChinaStates";
$azong = $db->Query($szong);
$zongshu = $azong[0][0]; //总条数
//造分页对象
$page = new Page($zongshu,15);
//在SQL语句拼接分页条件
$sql = "select * from ChinaStates ".$page->limit;
$attr = $db->Query($sql);
foreach($attr as $v)
{
echo "<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[3]}</td>
</tr>";
}
//总共 页 5/100 当前 页 首页 上一页 1,2,3,4,5,6 下一页 尾页 跳转到 页
?>
</table>
<div>
<?php
//返回分页信息
echo $page->fpage(4,5,6);
?>
</div>
</body>
</html>
分页加查询
两种提交方式,get、post
针对分页查询get相对简单,post略显复杂
get提交
form表单get提交到本页面
$tj = " 1=1 ";
$name="";
if(!empty($_GET["name"]) && $_GET["name"]!=""){
$tj = " AreaName like '%{$_GET['name']}%' ";
$name=$_GET["name"];
}
$ztj = " where {$tj}";
把条件变量 $ztj 拼接到sql语句后面
post提交
form表单post提交到本页面,首次可以,但是点列表时会刷新页面丢失post值
$tj = " 1=1 ";
$name="";
if(!empty($_POST["name"]) && $_POST["name"]!="")
{
$tj = " AreaName like '%{$_POST['name']}%' ";
$name=$_POST["name"];
}
if(!empty($_GET["name"]) && $_GET["name"]!="")
{
$tj = " AreaName like '%{$_GET['name']}%' ";
$name=$_GET["name"];
}
$ztj = " where {$tj}";
$posttj = "name={$name}";
将总条件拼接到sql语句后面,然后在创建page对象是,初始化第三个参数$posttj ,将post值方式变为get值方式