zoukankan      html  css  js  c++  java
  • 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>

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

  • 相关阅读:
    基于LBS(GPS)和ArcGIS的ITS智能交通 路况服务架构
    入手ipod touch4
    改2字节将Win XP Home变成Pro?!(zz)
    越来越多的同学在MSN上建Blog了……
    有了64位的芯不一定能运行64位OS?(zz)
    C++字符串完全指引之二——字符串封装类(zz)
    忙……
    注意C#中的ref及out关键字
    期待CGFTP 1.0正式版:)
    真伪双核 英特尔双核平台深度揭秘(zz)
  • 原文地址:https://www.cnblogs.com/zhaimiaoer/p/5518682.html
Copyright © 2011-2022 走看看