PHP 练习租房

时间:2023-03-09 13:08:09
PHP 练习租房

练习:租房子

<body>
<form action="test.php" method="post">
<div>区域:
<input type="checkbox" onclick="CheckAll(this,'qy')" />全选
</div>
<div>
<?php
include("../DBDA.php");
$db = new DBDA(); $sqlqy = "select distinct Area from housedb";
$attrqy = $db->Query($sqlqy); foreach($attrqy as $v)
{
echo "<input class='qy' type='checkbox' value='{$v[0]}' name='qy[]' />{$v[0]}&nbsp;";
} ?>
</div><br /> <div>租赁类型:
<input type="checkbox" onclick="CheckAll(this,'zl')" />全选
</div>
<div>
<?php
$sqlzl = "select distinct RentType from housedb";
$attrzl = $db->Query($sqlzl); foreach($attrzl as $v)
{
echo "<input class='zl' type='checkbox' value='{$v[0]}' name='zl[]' />{$v[0]}&nbsp;";
} ?>
</div><br /> <div>房屋类型:
<input type="checkbox" onclick="CheckAll(this,'fw')" />全选
</div>
<div>
<?php
$sqlfw = "select distinct HouseType from housedb";
$attrfw = $db->Query($sqlfw); foreach($attrfw as $v)
{
echo "<input class='fw' type='checkbox' value='{$v[0]}' name='fw[]' />{$v[0]}&nbsp;";
} ?>
</div><br /> <div>关键字:<input type="text" name="key" /></div>
<br />
<input type="submit" value="搜索" /> </form>
<br /> <table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>关键字</td>
<td>区域</td>
<td>建筑面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
</tr>
<?php $tj1 = " 1=1";
$tj2 = " 1=1";
$tj3 = " 1=1";
$tj4 = " 1=1"; if(!empty($_POST["qy"]))
{
$attr = $_POST["qy"];
$str = implode("','",$attr); $tj1 = " Area in ('{$str}')";
} if(!empty($_POST["zl"]))
{
$attr = $_POST["zl"];
$str = implode("','",$attr); $tj2 = " RentType in ('{$str}')";
} if(!empty($_POST["fw"]))
{
$attr = $_POST["fw"];
$str = implode("','",$attr); $tj3 = " HouseType in ('{$str}')";
} if(!empty($_POST["key"]))
{
$key = $_POST["key"];
$tj4 = " KeyWord like '%{$key}%'";
} $tj = " where {$tj1} and {$tj2} and {$tj3} and {$tj4}"; $sql = "select * from housedb".$tj; $attrall = $db->Query($sql); foreach($attrall as $v)
{
echo "<tr>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td>{$v[6]}</td>
</tr>";
} ?> </table> <script type="text/javascript"> function CheckAll(a,b)
{
var xz = a.checked;//找到全选的选中状态
var ck = document.getElementsByClassName(b); for(var i=0; i<ck.length;i++)
{
ck[i].checked = xz;
}
} </script>
</body>

---恢复内容结束---