您好,登錄后才能下訂單哦!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> </head> <body> <?php$db = new MySQLi("localhost","root","726","housedb");//一共有四個條件$tj1 = "1=1";$tj2 = "1=1";$tj3 = "1=1";$tj4 = "1=1";//區(qū)域的條件if(!empty($_POST["qx"]) && count($_POST["qx"])>0)//判斷區(qū)域有沒有傳入數(shù)據(jù),qs是一個數(shù)組 并且它數(shù)量大于0{ $qx = $_POST["qx"]; $str = implode("','",$qx); 分隔符 返回一個字符串 $tj1 = " area in('{$str}') "; }//租賃類型的條件if(!empty($_POST["zl"]) && count($_POST["zl"])>0) { $zl = $_POST["zl"]; //code in('類型','數(shù)量','都好久','隊伍','額') $str = implode("','",$zl); $tj2 = " renttype in('{$str}') "; }//房屋類型的條件if(!empty($_POST["fw"]) && count($_POST["fw"])>0) { $fw = $_POST["fw"]; //code in('類型','數(shù)量','都好久','隊伍','額') $str = implode("','",$fw); $tj3 = " housetype in('{$str}') "; }//關(guān)鍵字的條件if(!empty($_POST["key"])) { $key = $_POST["key"]; $tj4 = " keyword like '%{$key}%' "; } ?> <h2>租房子</h2> <form action="zfchaxun.php" method="post"> <div>區(qū)域:<input type="checkbox" onclick="checkall(this)" />全選</div> <div> <?php$sqlq = "select distinct area from house";$rq = $db->query($sqlq);$aq = $rq->fetch_all();foreach($aq as $v) { echo "<input type='checkbox' name='qx[]' value='{$v[0]}'> {$v[0]}"; } ?> </div> <br /> <div>租賃類型:<input type="checkbox" />全選</div> <div> <?php$sqlz = "select distinct renttype from house";$rz = $db->query($sqlz);$az = $rz->fetch_all();foreach($az as $v) { echo "<input type='checkbox' name='zl[]' value='{$v[0]}'> {$v[0]}"; //設(shè)置name值} ?> </div> <br /> <div>房屋類型:<input type="checkbox" />全選</div> <div> <?php$sqlf = "select distinct housetype from house";$rf = $db->query($sqlf);$af = $rf->fetch_all();foreach($af as $v) { echo "<input type='checkbox' name='lx[]' value='{$v[0]}'> {$v[0]}"; } ?> </div> <br /> <div>關(guān)鍵字:<input type="text" name="key" /> <input type="submit" value="查詢" /> </div> <br /> </form> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>關(guān)鍵字</td> <td>區(qū)域</td> <td>面積</td> <td>租金</td> <td>租賃類型</td> <td>房屋類型</td> </tr> <?php$sqlall = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";$rall = $db->query($sqlall);$aall = $rall->fetch_all();foreach($aall 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"> //實現(xiàn)復選框的全選function checkall(a) { var ck = document.getElementsByClassName("qxlist"); if(a.checked) { for(var i=0;i<ck.length;i++) { ck[i].setAttribute("checked","checked"); 復選框加個屬性 } } else { for(var i=0;i<ck.length;i++) { ck[i].removeAttribute("checked"); } } } </script> </body> </html>
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。