php第十七节课

分页查询

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>

<?php

//取提交的name值
$name = "";
$fytj = "";
if(!empty($_GET["name"]))
{
$name = $_GET["name"];
//分页查询条件
$fytj = "name={$name}";
}

//将name做为条件
$tj = " where AreaName like '%{$name}%' ";

?>
<br />
<div>
<form action="test.php" method="get">
<div>请输入名称:
<input type="text" name="name" value="<?php echo $name ?>" /> &nbsp;
<input type="submit" value="查询" />
</div>
</form>
</div>
<br />

<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>名称</td>
<td>父级代号</td>
</tr>
<?php

include("DBDA.php");
include("page.class.php");

$db = new DBDA();

//查询总记录数
$sqlall = "select count(*) from ChinaStates".$tj;
$attrall = $db->Query($sqlall);

$total = $attrall[0][0];

$page = new Page($total,15,$fytj,true);


$sql = "select * from ChinaStates ".$tj.$page->limit;
$attr = $db->Query($sql);

foreach($attr as $v)
{
echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td></tr>";
}

?>
</table>
<div>
<?php
echo $page->fpage();
?>
</div>
</body>
</html>

原文地址:https://www.cnblogs.com/xiongxiaobai/p/5485280.html