您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)php如何實(shí)現(xiàn)出租房數(shù)據(jù)管理及搜索頁(yè)面,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
php數(shù)據(jù)訪問(wèn)例子:租房信息管理,具體內(nèi)容如下
1.數(shù)據(jù)庫(kù)建表
2. zufangzi.php
<body> <h2>租房子</h2> <form action="zufangzi.php" method="post"> <div>區(qū)域:<input type="checkbox" name="qx" onclick="quanxuan(this,'qy')" />全選</div> <div> <?php require "DBDA.class1.php"; $db = new DBDA(); $sqy = "select distinct area from house";//寫(xiě)SQL語(yǔ)句,并去重 $aqy = $db->query($sqy); foreach($aqy as $v) { echo "<input type='checkbox' name='qy[]' value='{$v[0]}' class='qy' />{$v[0]}"; } ?> </div> <br /> <div>租賃類(lèi)型:<input type="checkbox" name="zlqx" onclick="quanxuan(this,'zl')" />全選</div> <div> <?php $szl = "select distinct renttype from house"; $azl = $db->query($szl); foreach($azl as $v) { echo "<input type='checkbox' name='zl[]' value='{$v[0]}' class='zl' />{$v[0]}"; } ?> </div> <br /> <div>房屋類(lèi)型:<input type="checkbox" name="fwqx" onclick="quanxuan(this,'fw')" />全選</div> <div> <?php $sfw = "select distinct housetype from house"; $afw = $db->query($sfw); foreach($afw as $v) { echo "<input type='checkbox' name='fw[]' value='{$v[0]}' class='fw' />{$v[0]}"; } ?> </div> <br /> <div>關(guān)鍵字:<input type="text" name="key" /> <input type="submit" value="查詢(xún)" /></div> </form> <br /> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>關(guān)鍵字</td> <td>區(qū)域</td> <td>建筑面積</td> <td>租金</td> <td>租賃類(lèi)型</td> <td>房屋類(lèi)型</td> </tr> <?php $tj1 = " 1=1 "; $tj2 = " 1=1 "; $tj3 = " 1=1 "; $tj4 = " 1=1 "; if(!empty($_POST["qy"])) { $aqy = $_POST["qy"]; $sqy = implode("','",$aqy); $tj1 = " area in ('{$sqy}') "; } if(!empty($_POST["zl"])) { $azl = $_POST["zl"]; $szl = implode("','",$azl); $tj2 = " renttype in ('{$szl}') "; } if(!empty($_POST["fw"])) { $afw = $_POST["fw"]; $sfw = implode("','",$afw); $tj3 = " housetype in ('{$sfw}') "; } if(!empty($_POST["key"])) { $k = $_POST["key"]; $tj4 = " keyword like '%{$k}%' "; } $sql = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}"; echo $sql; $arr = $db->query($sql); foreach($arr 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> </body> <script type="text/javascript"> function quanxuan(qx,a) { //找到該全選按鈕對(duì)應(yīng)的checkbox列表 var ck = document.getElementsByClassName(a); //找全選按鈕選中狀態(tài) if(qx.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> </html>
所引用的封裝類(lèi)
<?php class DBDA { public $host = "localhost"; public $uid = "root"; public $pwd = "123"; public $dbname = "test_123"; //執(zhí)行SQL語(yǔ)句返回相應(yīng)的結(jié)果 //$sql 要執(zhí)行的SQL語(yǔ)句 //$type 代表SQL語(yǔ)句的類(lèi)型,0代表增刪改,1代表查詢(xún) function query($sql,$type=1) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $result = $db->query($sql); if($type) { //如果是查詢(xún),顯示數(shù)據(jù) return $result->fetch_all(); } else { //如果是增刪改,返回true或者false return $result; } } }
呈現(xiàn)頁(yè)面
關(guān)于“php如何實(shí)現(xiàn)出租房數(shù)據(jù)管理及搜索頁(yè)面”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。