<h1>租房信息</h1> <?php $db = new MySQLi("localhost","root","456","asdadads"); $tj = "1=1"; $tj1 = "1=1"; $name = ""; if(!empty ($_POST["name"])) { $name = $_POST["name"]; $tj = "keyword like '%{$name}%'"; } if(!empty ($_POST["area"])) { $area = $_POST["area"]; $tj1= "$area = '{$area}'"; } ?> <form action="zufang.php" method="post"> <div> 关键字: <input type="text" name="name" value="<?php echo $name ?>" /> 请输入区域: <input type="text" name="area" /> <input type="submit" value="查询" /> </div> </form> </br> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>唯一标识</td> <td>关键字</td> <td>所属区域</td> <td>使用面积(平米)</td> <td>租金(每月)</td> <td>租房类型</td> <td>房屋类型</td> </tr> <?php //$db = new MySQLi("localhost","root","456","asdadads"); $sql = "select * from zufang where {$tj} and {$tj1}"; echo $sql; $r= $db->query($sql); $attr= $r->fetch_all(); if(count($attr)>0) { foreach( $attr as $v) { $str = str_replace($name,"<mark>{$name}</mark>",$v[1]); echo " <tr> <td>{$v[0]}</td> <td>{$str}</td> <td>{$v[2]}</td>
<td>{$v[3]}</td> <td>{$v[4]}</td> <td>{$v[5]}</td> <td>{$v[6]}</td> </tr>"; } } el { echo "<script>alert('没有查到数据');</script>"; } ?>