1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 </head> 7 8 <body> 9 <?php 10 11 $db = new MySQLi("localhost","root","123","housedb"); 12 13 $tj1 = " 1=1 "; 14 $tj2 = " 1=1 "; 15 $tj3 = " 1=1 "; 16 $tj4 = " 1=1 "; 17 18 //区域的条件 19 if(!empty($_POST["qx"]) && count($_POST["qx"])>0) 20 { 21 //$tj1 = ""; 22 $qx = $_POST["qx"]; 23 //code in(‘类型‘,‘数量‘,‘都好久‘,‘队伍‘,‘额‘) 24 $str = implode("‘,‘",$qx); 25 26 $tj1 = " area in(‘{$str}‘) "; 27 } 28 //租赁类型的条件 29 if(!empty($_POST["zl"]) && count($_POST["zl"])>0) 30 { 31 //$tj1 = ""; 32 $zl = $_POST["zl"]; 33 //code in(‘类型‘,‘数量‘,‘都好久‘,‘队伍‘,‘额‘) 34 $str = implode("‘,‘",$zl); 35 36 $tj2 = " renttype in(‘{$str}‘) "; 37 } 38 //房屋类型的条件 39 if(!empty($_POST["fw"]) && count($_POST["fw"])>0) 40 { 41 //$tj1 = ""; 42 $fw = $_POST["fw"]; 43 //code in(‘类型‘,‘数量‘,‘都好久‘,‘队伍‘,‘额‘) 44 $str = implode("‘,‘",$fw); 45 46 $tj3 = " housetype in(‘{$str}‘) "; 47 } 48 //关键字的条件 49 if(!empty($_POST["key"])) 50 { 51 $key = $_POST["key"]; 52 $tj4 = " keyword like ‘%{$key}%‘ "; 53 } 54 55 ?> 56 57 <h1>租房子</h1> 58 59 <form action="test.php" method="post"> 60 61 <div>区域:<input type="checkbox" onclick="checkall(this)" />全选</div> 62 <div> 63 <?php 64 $sqlq = "select distinct area from house"; 65 $rq = $db->query($sqlq); 66 $aq = $rq->fetch_all(); 67 foreach($aq as $v) 68 { 69 echo "<input type=‘checkbox‘ name=‘qx[]‘ value=‘{$v[0]}‘ class=‘qxlist‘ />{$v[0]} "; 70 } 71 ?> 72 </div> 73 <br /> 74 <div>租赁类型:<input type="checkbox" />全选</div> 75 <div> 76 <?php 77 $sqlz = "select distinct renttype from house"; 78 $rz = $db->query($sqlz); 79 $az = $rz->fetch_all(); 80 foreach($az as $v) 81 { 82 echo "<input type=‘checkbox‘ name=‘zl[]‘ value=‘{$v[0]}‘ />{$v[0]} "; 83 } 84 ?> 85 </div> 86 <br /> 87 <div>房屋类型:<input type="checkbox" />全选</div> 88 <div> 89 <?php 90 $sqlf = "select distinct housetype from house"; 91 $rf = $db->query($sqlf); 92 $af = $rf->fetch_all(); 93 foreach($af as $v) 94 { 95 echo "<input type=‘checkbox‘ name=‘fw[]‘ value=‘{$v[0]}‘ />{$v[0]} "; 96 } 97 ?> 98 </div> 99 <br /> 100 <div>关键字:<input type="text" name="key" /> 101 <input type="submit" value="查询" /> 102 </div> 103 <br /> 104 105 </form> 106 <table width="100%" border="1" cellpadding="0" cellspacing="0"> 107 <tr> 108 <td>关键字</td> 109 <td>区域</td> 110 <td>面积</td> 111 <td>租金</td> 112 <td>租赁类型</td> 113 <td>房屋类型</td> 114 </tr> 115 <?php 116 117 $sqlall = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}"; 118 $rall = $db->query($sqlall); 119 $aall = $rall->fetch_all(); 120 foreach($aall as $v) 121 { 122 echo "<tr> 123 <td>{$v[1]}</td> 124 <td>{$v[2]}</td> 125 <td>{$v[3]}</td> 126 <td>{$v[4]}</td> 127 <td>{$v[5]}</td> 128 <td>{$v[6]}</td> 129 </tr>"; 130 } 131 ?> 132 133 </table> 134 135 <script type="text/javascript"> 136 137 function checkall(a) 138 { 139 var ck = document.getElementsByClassName("qxlist"); 140 //注意checked 的属性 无论题中有没有写 都有默认值 所以 可以写城下面 方式 其他 以此类推 其他的的如果 里面没有的属性(比如 a 自己定义的 需要 attribute() 属性添加) 141 if(a.checked) 142 { 143 for(var i=0;i<ck.length;i++) 144 { 145 /*ck[i].setAttribute("checked","checked");*/ 146 ck[i].checked="checked"; 147 } 148 } 149 else 150 { 151 for(var i=0;i<ck.length;i++) 152 { 153 /*ck[i].removeAttribute("checked");*/ 154 ck[i].checked=""; 155 } 156 } 157 } 158 159 </script> 160 </body> 161 </html>
时间: 2024-10-17 14:32:24