1.先把数据库里所有的数据分页显示在页面,并在显示数据的表格上方加上查询表单。

<!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>
<br />
<form action="fenyechaxun.php" method="get"><!--分页查询最好使用get,不要使用post,使用post会变得很复杂。-->
<div>关键字:<input type="text" name="key" />
<input type="submit" value="查询" />
</div>
</form>
<br />
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>地区代号</th><!--坐标头-->
<th>地区名称</th>
<th>上级代号</th>
</tr>
<?php
include("DBDA.class.php");//引入封装类的页面
$db = new DBDA();//造一个对象 //求数据的总条数
$sall = "select count(*) from chinastates";
$total = $db->StrQuery($sall); include("page.class.php");//引入分页类的页面
$page = new Page($total,20);//造一个分页的对象.第一个参数是数据的总条数,第二个参数是每页显示多少条数据。 $sql = "select * from chinastates ".$page->limit;//调用分页里面的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>
<?php
echo $page->fpage();//显示表格下方的数据和页面的信息。
?>
</body>
</html>

2.加上条件,实现目标结果。

<!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>
<br />
<form action="fenyechaxun.php" method="get">
<div>关键字:<input type="text" name="key" />
<input type="submit" value="查询" />
</div>
</form>
<br />
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>地区代号</th>
<th>地区名称</th>
<th>上级代号</th>
</tr>
<?php
include("DBDA.class.php");
$db = new DBDA(); //查询条件
$tj1 = " 1=1 ";
if(!empty($_GET["key"]))//获取提交的关键字
{
$tj1 = " areaname like '%{$_GET['key']}%'";
} $sall = "select count(*) from chinastates where {$tj1}";//把条件拼接到语句中
$total = $db->StrQuery($sall); include("page.class.php");
$page = new Page($total,20); $sql = "select * from chinastates where {$tj1} ".$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>
<?php
echo $page->fpage();
?>
</body>
</html>

最新文章

  1. H3C汇聚层交换机认证在线人数展示系统之需求说明和功能点说明
  2. CSS3使用AnimationEnd为同一个元素添加多个动画效果
  3. 初识UML
  4. 做一个高效的IOS开发工程师
  5. 20145207 《Java程序设计》第5周学习总结
  6. Upgrading to MySQL 5.7---focusing on temporal types
  7. 权重随机算法的java实现
  8. (转)A drop-in universal solution for moving text fields out of the way of the keyboard
  9. 利用WinDbg找出程序崩溃的代码行号
  10. ecshop后台增加模块菜单项详细教程(图文)
  11. CENTOS6.6下mysql MMM架构搭建
  12. 【一天一道LeetCode】#258. Add Digits
  13. 判断语句之单if
  14. kafka配置项host.name advertised.host.name
  15. Spring cloud Eureka错误锦集(二)
  16. vsftpd虚拟账户配置
  17. pandas分组group
  18. hdu 1756(判断点是否在多边形中)
  19. MonkeyRunner原理初步--Android自动化测试学习历程
  20. requestAnimationFrame 优雅降级

热门文章

  1. LintCode-374.螺旋矩阵
  2. iOS开发UUIView动画方法总结
  3. 累积下学习 C#时和 Java时的不同点
  4. 从Mysql某一表中随机读取n条数据的SQL查询语句
  5. [剑指Offer] 46.孩子们的游戏
  6. bzoj3502[PA2012]Tanie Linie(最大k区间和)
  7. BZOJ4755 JSOI2016扭动的回文串(二分答案+哈希)
  8. kafka搭建笔记
  9. [洛谷P2774]方格取数问题
  10. ARC077D 11 组合数