• 租房子例题


      1 <body>
      2 
      3 <h1>租房子</h1>
      4 
      5 <form action="zufangzi.php" method="post">
      6 <div>区域:<input type="checkbox" name="qx" onclick="quanxuan(this,'qy')" />全选</div>
      7 <div>
      8 <?php
      9 require "../0428/DBDA.class.php";
     10 $db = new DBDA();
     11 
     12 $sqy = "select distinct area from housedb";
     13 $aqy = $db->query($sqy);
     14 foreach($aqy as $v)
     15 {
     16     echo "<input type='checkbox' name='qy[]' value='{$v[0]}' class='qy' />{$v[0]}";
     17 }
     18 ?>
     19 </div>
     20 <br />
     21 
     22 <div>租赁类型:<input type="checkbox" name="zlqx" onclick="quanxuan(this,'zl')" />全选</div>
     23 <div>
     24 <?php
     25 $szl = "select distinct renttype from housedb";
     26 $azl = $db->query($szl);
     27 foreach($azl as $v)
     28 {
     29     echo "<input type='checkbox' name='zl[]' value='{$v[0]}' class='zl' />{$v[0]}";
     30 }
     31 ?>
     32 </div>
     33 <br />
     34 <div>房屋类型:<input type="checkbox" name="fwqx" onclick="quanxuan(this,'fw')" />全选</div>
     35 <div>
     36 <?php
     37 $sfw = "select distinct housetype from housedb";
     38 $afw = $db->query($sfw);
     39 foreach($afw as $v)
     40 {
     41     echo "<input type='checkbox' name='fw[]' value='{$v[0]}' class='fw' />{$v[0]}";
     42 }
     43 ?>
     44 </div>
     45 <br />
     46 <div>关键字:<input type="text" name="key" /> <input type="submit" value="查询" /></div>
     47 </form>
     48 <br />
     49 
     50 <table width="100%" border="1" cellpadding="0" cellspacing="0">
     51     <tr>
     52         <td>关键字</td>
     53         <td>区域</td>
     54         <td>建筑面积</td>
     55         <td>租金</td>
     56         <td>租赁类型</td>
     57         <td>房屋类型</td>
     58     </tr>
     59     <?php
     60     
     61     $tj1 = " 1=1 ";
     62     $tj2 = " 1=1 ";
     63     $tj3 = " 1=1 ";
     64     $tj4 = " 1=1 ";
     65     
     66     if(!empty($_POST["qy"]))
     67     {
     68         $aqy = $_POST["qy"];
     69         $sqy = implode("','",$aqy);
     70         
     71         $tj1 = " area in ('{$sqy}') ";
     72     }
     73     
     74     if(!empty($_POST["zl"]))
     75     {
     76         $azl = $_POST["zl"];
     77         $szl = implode("','",$azl);
     78         
     79         $tj2 = " renttype in ('{$szl}') ";
     80     }
     81     
     82     if(!empty($_POST["fw"]))
     83     {
     84         $afw = $_POST["fw"];
     85         $sfw = implode("','",$afw);
     86         
     87         $tj3 = " housetype in ('{$sfw}') ";
     88     }
     89     
     90     if(!empty($_POST["key"]))
     91     {
     92         $k = $_POST["key"];
     93         $tj4 = " keyword like '%{$k}%' ";
     94     }
     95     
     96     
     97     $sql = "select * from housedb where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
     98     echo $sql;
     99     
    100     $arr = $db->query($sql);
    101     foreach($arr as $v)
    102     {
    103         echo "<tr>
    104         <td>{$v[1]}</td>
    105         <td>{$v[2]}</td>
    106         <td>{$v[3]}</td>
    107         <td>{$v[4]}</td>
    108         <td>{$v[5]}</td>
    109         <td>{$v[6]}</td>
    110     </tr>";
    111     }
    112     ?>
    113 </table>
    114 
    115 </body>
    116 <script type="text/javascript">
    117 function quanxuan(qx,a)
    118 {
    119     //找到该全选按钮对应的checkbox列表
    120     var ck = document.getElementsByClassName(a);
    121     //找全选按钮选中状态
    122     if(qx.checked)
    123     {
    124         for(var i=0;i<ck.length;i++)
    125         {
    126             ck[i].setAttribute("checked","checked");
    127         }
    128     }
    129     else
    130     {
    131         for(var i=0;i<ck.length;i++)
    132         {
    133             ck[i].removeAttribute("checked");
    134         }
    135     }
    136     
    137 }
    138 </script>
    139 </html>
  • 相关阅读:
    POJ 2195 Going Home(费用流)
    HDU 2485 Destroying the bus stations(费用流)
    POJ 3281 Dining(最大流)
    POJ 1122 FDNY to the Rescue!(最短路+路径输出)
    HDU 4747 Mex(线段树)
    POJ 2337 Catenyms
    UVa 10328 Coin Toss(Java大数+递推)
    HDU 1811 Rank of Tetris(拓扑排序+并查集)
    ZOJ 3747 Attack on Titans
    UVa 11404 回文子序列(LCS求最长回文串长度)
  • 原文地址:https://www.cnblogs.com/zqld/p/6813862.html
Copyright © 2020-2023  润新知