然后就是form表单中提交查询的数据,这里以post方式提交到本页面,所以要判断post中是否有值,在判断post中的值是否为空字符串(这两种情况都默认用户没有输入,查询所有)默认规则:一般来说做查询的时候:用户不输入任何内容就是查询所有的
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h1>查询系统</h1>
<Form action="danchaxun.php" method="post">
请输入汽车名称:
<input type="text" name = "name" />
请输入汽车系列:
<input type="text" name = "brand" />
<input type="submit" value="查询" />
</Form>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>名字</td>
<td>系列</td>
<td>出厂时间</td>
<td>油耗</td>
<td>功率</td>
</tr>
<?php
include ("DBDA.class.php");
$db = new DBDA();
$tj1 = " 1=1";
$tj2 = " 1=1";
$name = "";
if(!empty($_POST)){
if($_POST["name"] != ""){
$name = $_POST["name"];
$tj1 = " name like ‘%{$name}%‘";
}
if($_POST["brand"] != ""){
$tj2 = " brand = ‘{$_POST[‘brand‘]}‘";
}
}
$tj = " where ".$tj1." and ".$tj2;
$sql = "select * from car ".$tj;
$attr = $db->Query($sql);
foreach($attr as $v){
echo "
<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
</tr>
";
}
?>
</table>
</body>
</html>