<!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> <h1>汽车表</h1> <?php include("../DBDA.php"); $db=new DBDA(); //查询时查询框里面显示用 $value1=""; $value2=""; //select语句条件用 条件必须是恒等的 $cx=""; $tj1=" 1=1"; $tj2=" 1=1"; if(!empty($_POST["name"])) { $tj1=" name like '%{$_POST['name']}%'"; $value1=$_POST["name"]; } if(!empty($_POST["brand"])) { $tj2=" brand='{$_POST['brand']}'"; $value2=$_POST["brand"]; } $cx=" where {$tj1} and {$tj2}"; ?> <form action="dtjchaxun.php" method="post"> <div> 请输入名称:<input type="text" name="name" value="<?php echo $value1 ?>"/> 请输入系列:<input type="text" name="brand" value="<?php echo $value2 ?>"/> <input type="submit" value="查询" /> </div> </form> <table border="1" width="100%" cellpadding="0" cellspacing="0"> <tr> <td>代号</td> <td>名称</td> <td>系列</td> <td>时间</td> <td>油耗</td> <td>价格</td> </tr> <?php $sql="select * from car".$cx; $zhi=$db->Query($sql); foreach($zhi as $v) { $daiti1="<mark>{$value1}</mark>"; $daiti2="<mark>{$value2}</mark>"; $th1=str_replace($value1,$daiti1,$v[1]); $th2=str_replace($value2,$daiti2,$v[2]); echo"<tr> <td>{$v[0]}</td> <td>{$th1}</td> <td>{$th2}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td>{$v[7]}</td> </tr>"; } ?> </table> </body> </html>
页面不查询的时候显示
查询时页面显示