PHP 练习租房

Posted 翟喵儿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

 

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

以上是关于PHP 练习租房的主要内容,如果未能解决你的问题,请参考以下文章

链家深圳租房信息爬取练习 附加源码

租房子查询练习

PHP连接数据库实现多条件查询与分页功能——关于租房页面的完整实例操作

php租房题目

PHP制作查询租房表

PHP多条件查询 (租房查询)