<!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="";$fytj=""; if(!empty($_GET["name"])) { $name=$_GET["name"]; $fytj="name=‘{$name}‘";//这个如果是get可以省略,默认自动加载 } $tj=" where AreaName like ‘%{$name}%‘ "; ?> <div> <form action="0512am-query.php" method="get">//一般form里method用post,这里用get,因为需要获取name的值还要在地址栏里面显示page 请输入名称:<input type="text" name="name" value="<?php echo $name;?>" /> <input type="submit" value="查询" /> </form> </div><br /> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>区域代号</td> <td>名称</td> <td>父级区域代号</td> </tr> <?php include("ChaXun.class.php"); $db=new ChaXun(); $sqlall="select count(*) from chinastates".$tj;//拼上where条件,需要注意where前面加空格 $attrall=$db->Query($sqlall); $total=$attrall[0][0]; include("page.class.php"); $page=new Page($total,20); $sql="select * from chinastates ".$tj.$page->limit;//拼上where条件,需要注意where前面的空格,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>
get方法!
post方法需要改动一下
<body> <?php $name=""; $fytj=""; if(!empty($_POST["name"]))//多判断一次post { $name=$_POST["name"]; $fytj="name=‘{$name}‘";//加一个条件 } if(!empty($_GET["name"])) { $name=$_GET["name"]; } $tj=" where AreaName like ‘%{$name}%‘ "; ?> <div> <form action="0512am-query.php" method="post">//method改为post 请输入名称:<input type="text" name="name" value="<?php echo $name;?>" /> <input type="submit" value="查询" /> </form> </div><br /> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>区域代号</td> <td>名称</td> <td>父级区域代号</td> </tr> <?php include("ChaXun.class.php"); $db=new ChaXun(); $sqlall="select count(*) from chinastates".$tj; $attrall=$db->Query($sqlall); $total=$attrall[0][0]; include("page.class.php"); $page=new Page($total,20); $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>
时间: 2024-10-14 14:10:08