zoukankan      html  css  js  c++  java
  • 5月9日 练习:租房子

    通过选项查询数据并在页面显示

    列出查询的具体条件;

    <body>
    <form action="zu,php" method="post">
    <div>区域:
    <input type="checkbox"  onclick="CheckAll(this,'qy')"/>全选</div>
    <?php
    include("DBDA.class.php");
    $db = new DBDA();
    $sqlqy = "select distinct Area from house";
    $atr = $db->Query($sqlqy,0,"housedb");
    foreach($atr as $v)
    {
        echo "<input type='checkbox' class='qy' value='{$v[0]}' name='qy[]'/>{$v[0]}
        ";
    }
    ?>
    <div><br/></div>
    <div>租赁类型:
    <input type="checkbox"  onclick="CheckAll(this,'zl')"/>全选</div>
    <?php
    $sqlzl = "select distinct RentType from house";
    $atr = $db->Query($sqlzl,0,"housedb");
    foreach($atr as $v)
    {
        echo "<input type='checkbox' class='zl' value='{$v[0]}' name='zl[]'/>{$v[0]}
        ";
    }
    ?>
    <div><br/></div>
    <div>房屋类型:
    <input type="checkbox" onclick="CheckAll(this,'fw')"/>全选</div>
    <?php
    $sqlfw = "select distinct HouseType from house";
    $atr = $db->Query($sqlfw,0,"housedb");
    foreach($atr as $v)
    {
        echo "<input type='checkbox' class='fw' value='{$v[0]}' name='fw[]'/>{$v[0]}
        ";
    }
    ?>
    <div><br/></div>
    <div>关键字:<input type="text" name="key" /></div>
    
    <input type="submit" value="搜索"/>
    </form>

    多条件查询,数据以表格的形式显示;

    <table width="100%" cellpadding="0" cellspacing="0" border="1">
    <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"]))
    {
        $str = $_POST["qy"];
        $attr = implode("','",$str);
        $tj1 = "Area in ('{$attr}')";
    }
    if(!empty($_POST["zl"]))
    {
        $str = $_POST["zl"];
        $attr = implode("','",$str);
        $tj2 = "RentType in ('{$attr}')";
    }
    if(!empty($_POST["fw"]))
    {
        $str = $_POST["fw"];
        $attr = implode("','",$str);
        $tj3 = "Housetype in ('{$attr}')";
    }
    if(!empty($_POST["key"]))
    {
        $key = $_POST["key"];
        $tj4 = "keyword like '%{$_POST['key']}%'";
    }
    $tj =" where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
    $sql = "select * from house".$tj;
    $result = $db->Query($sql,0,"housedb");
    foreach($result 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>
  • 相关阅读:
    boost常用记录
    redis系列-redis的持久化
    分布式存储的一些概念
    搜索引擎学习-实现
    搜索引擎学习-概述
    设计模式-创建型模式(读书笔记)
    redis系列-redis的使用场景
    分布式系统设计准则
    2018/12/06 eclipse 快速加载需要的包
    2018/12/06 L1-028 判断素数 Java
  • 原文地址:https://www.cnblogs.com/dongqiaozhi/p/5477555.html
Copyright © 2011-2022 走看看