<?php $name = ""; 查询所取到的name的值 $fytj = ""; if(!empty($_GET["name"])) { $name = $_GET["name"]; $fytj = "name={$name}"; 分页查询的条件 } $tj = " where AreaName like '%{$name}%' "; 把取到的name值写到查询条件中 ?> <br /> <div> <form action="test.php" method="get"> <div>请输入名称: <input type="text" name="name" value="<?php echo $name ?>" /> <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>