php租房題目
阿新 • • 發佈:2018-01-21
lod vertica div bmi w3c 字符 function 代碼 ansi
<!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> <h1>租房子</h1> <?php //這段php邏輯需要提到這裏 require_once "DBDA.class.php"; //加載DBDA類 $db = new DBDA(); $tj1 = " 1=1 "; //做條件 做成恒成立 總共四個條件查詢 $tj2 = " 1=1 "; $tj3 = " 1=1 "; $tj4 = " 1=1 "; $arr1 = array(); //花括號內的arr1需要提到外面用做出查詢數據時可以顯示選擇的數據 if(!empty($_POST["qy"])){ //判斷qy數組是否為空 // area in (‘‘,‘‘,‘‘,‘‘) //用in方法取出做成拼接 $arr1 = $_POST["qy"]; //取出數組存進變量 $str = implode("‘,‘",$arr1); //implode方法拼接字符串 $tj1 = " area in (‘{$str}‘) "; //條件1變成 area拼接 } $arr2 = array(); if(!empty($_POST["zl"])){ // area in (‘‘,‘‘,‘‘,‘‘) $arr2 = $_POST["zl"]; $str = implode("‘,‘",$arr2); $tj2 = " rentype in (‘{$str}‘) "; } $arr3 = array(); if(!empty($_POST["fw"])){ // area in (‘‘,‘‘,‘‘,‘‘) $arr3 = $_POST["fw"]; $str = implode("‘,‘",$arr3); $tj3 = " housetype in (‘{$str}‘) "; } $key = ""; if(!empty($_POST["key"])){ $key = $_POST["key"]; $tj4 = " keyword like ‘%{$key}%‘ "; //like模糊查詢 }?> <form action="main.php" method="post"> //做出表單提交 <div> 區域:<input type="checkbox" id="qy" />全選<br /> //做全選按鈕id=qy class=qy <?php $sqlqy = "select distinct area from housedb"; //查詢去重 $arrqy = $db->query($sqlqy); //展示出所有的區域信息 foreach($arrqy as $v){ if(in_array($v[0],$arr1)){ //用in_array做出if輸出選中和不選中的兩種結果 echo "<input class=‘qy‘ type=‘checkbox‘ name=‘qy[]‘ value=‘{$v[0]}‘ checked=‘checked‘ />{$v[0]} "; }else{ echo "<input class=‘qy‘ type=‘checkbox‘ name=‘qy[]‘ value=‘{$v[0]}‘ />{$v[0]} "; } }?> </div> <br /> <div> 租賃類型:<input type="checkbox" id="zl" />全選<br /> <?php $sqlzl = "select distinct renttype from housedb"; $arrzl = $db->query($sqlzl); foreach($arrzl as $v){ if(in_array($v[0],$arr2)){ echo "<input class=‘zl‘ type=‘checkbox‘ name=‘zl[]‘ value=‘{$v[0]}‘ checked=‘checked‘ />{$v[0]} "; }else{ echo "<input class=‘zl‘ type=‘checkbox‘ name=‘zl[]‘ value=‘{$v[0]}‘ />{$v[0]} "; } } ?> </div> <br /> <div> 房屋類型:<input type="checkbox" id="fw" />全選<br /> <?php $sqlfw = "select distinct housetype from housedb"; $arrfw = $db->query($sqlfw); foreach($arrfw as $v){ if(in_array($v[0],$arr3)){ echo "<input class=‘fw‘ type=‘checkbox‘ name=‘fw[]‘ value=‘{$v[0]}‘ checked=‘checked‘ />{$v[0]} "; }else{ echo "<input class=‘fw‘ type=‘checkbox‘ name=‘fw[]‘ value=‘{$v[0]}‘ />{$v[0]} "; } } ?> </div> <br /> <div> 關鍵字:<input type="text" name="key" value=‘<?php echo $key; ?>‘ /> //value取key顯示選擇的數據 </div> <br /> <div> <input type="submit" value="搜索" /> //提交按鈕 </div> <br /> </form> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>關鍵字</td> //用表格方法顯示數據 <td>區域</td> <td>建築面積</td> <td>租金</td> <td>租賃類型</td> <td>房屋類型</td> </tr> <?php //寫phpsql語句調用數據庫顯示數據信息 $sql = "select * from housedb 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"> //用js做出全選的效果 var qy = document.getElementById("qy"); //找到qy qy.onclick = function(){ //加點擊事件 var zt = qy.checked; //定義qy的狀態屬性 var ck = document.getElementsByClassName("qy"); //找到所有區域的checkbox的=選中狀態 for(var i=0;i<ck.length;i++){ //循環遍歷 ck[i].checked = zt; ck取索引i得到每個曉得checkbox=checked } } var zl = document.getElementById("zl"); zl.onclick = function(){ var zt = zl.checked; var ck = document.getElementsByClassName("zl"); for(var i=0;i<ck.length;i++){ //{}花括號是作用域 花括號內重復內容沒有關系 ck[i].checked = zt; } } var fw = document.getElementById("fw"); fw.onclick = function(){ var zt = fw.checked; var ck = document.getElementsByClassName("fw"); for(var i=0;i<ck.length;i++){ ck[i].checked = zt; } } </script> </html>
以下是增刪改的做法
3.租房子首頁
<!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> <table width="1000px" cellpadding="1" border="1" ellspacing="1"> <tr> <td>關鍵字</td> <td>區域</td> <td>使用面積</td> <td>租金</td> <td>租貸類型</td> <td>房屋類型</td> <td></td> <td></td> </tr>
<?php include("DBDA.class.php"); $dx=new DBDA(); $sql="select * from house"; $r = $dx->Query($sql,1); //$attr=$result->fetch_all(); foreach($r 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> <td><a href=‘bianji.php?id={$v[0]}‘>編輯</a></td> <td><a href=‘shanchuchuli.php?id={$v[0]}‘ onclick=\"return confirm(‘確定刪除嗎‘)\">刪除</a></td> </tr>"; } ?>
</table> <br /> <br /> <a href="tianjiashuju.php"><input type="button" value="添加數據"/></a> <a href="duotiaojianchaxun.php"><input type="button" value="搜索查詢" /></a> </title> </body> </html>
(4)刪除數據處理頁面
<?php $id = $_GET["id"]; var_dump($newsid); include("DBDA.class.php"); $dx=new DBDA(); $sql = "delete from House where id=‘{$id}‘"; $r = $dx->Query($sql,2); if($r) { header("location:liebiaoyemian.php"); } else { echo "刪除失敗!"; }
5.編輯頁面
<!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> <!--newsid--><center> <h1>修改房屋數據</h1>
<?php $id = $_GET["id"]; include("DBDA.class.php"); $dx=new DBDA(); //echo "id"; //var_dump($id); $sql="select * from house where id=‘{$id}‘"; $r=$dx->Query($sql); ?>
<form action="bianjichuli.php" method="post"> <input type="hidden" name="id" value="<?php echo $r[0][0];?>"/><!--id傳過的ID--> <div>關鍵字:<input type="text" name="KeyWord" value="<?php echo $r[0][1];?>"/></div> <div>區域:<input type="text" name="Area" value="<?php echo $r[0][2];?>"/></div> <div>使用面積:<input type="text" name="SquareMeter" value="<?php echo $r[0][3];?>"/></div> <div>租金:<input type="text" name="Rent" value="<?php echo $r[0][4];?>"/></div> <div>租貸類型:<input type="text" name="RentType" value="<?php echo $r[0][5];?>"/></div> <div>房屋類型:<input type="text" name="HouseType" value="<?php echo $r[0][6];?>"/></div> <div><input type="submit" value="更新"/></div> </form> <!--<a href="chakan.php"><input type="button" value="查看"></a>--> </center> </body> </html>
6.編輯處理頁面
<?php //使用加載類 include("DBDA.class.php"); $db = new DBDA(); $id=$_POST["id"];//傳ID $KeyWord = $_POST["KeyWord"]; $Area = $_POST["Area"]; $SquareMeter = $_POST["SquareMeter"]; $Rent = $_POST["Rent"]; $RentType = $_POST["RentType"]; $HouseType = $_POST["HouseType"]; $sql="update house set KeyWord=‘{$KeyWord}‘,Area=‘{$Area}‘,SquareMeter=‘{$SquareMeter}‘,Rent=‘{$Rent}‘,RentType=‘{$RentType}‘,HouseType=‘{$HouseType}‘ where id=‘{$id}‘";// where id=‘{$id} //echo $sql; $attr = $db->Query($sql,2); //var_dump($attr); if($attr) { header("location:liebiaoyemian.php"); } else { echo "修改失敗"; }
7.添加數據頁面
<!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> <style> .kong { margin:10px 0px 10px 0px; vertical-align: } </style> <body> <form action="tianjiachili.php" method="post"> <h3>添加房屋信息頁面</h3> <div class="kong"> 關鍵字: <input type="text" name="KeyWord"/> </div> <div class="kong"> 區域: <input type="text" name="Area"/> </div> <div class="kong"> 使用面積: <input type="text" name="SquareMeter"/> </div> <div class="kong"> 租金: <input type="text" name="Rent"> </div> <div class="kong"> 租賃類型: <input type="text" name="RentType"/> </div> <div class="kong"> 房屋類型 <input type="text" name="HouseType"/> </div> <div> <input type="submit" value="確定"/><!--插入信息--> <a href="liebiaoyemian.php"><input type="button" value="返回主頁" /></a> </div> </form> </body> </html>
8.添加數據處理頁面
<?php //$id = $_POST["id"]; $KeyWord = $_POST["KeyWord"]; $Area = $_POST["Area"]; $SquareMeter = $_POST["SquareMeter"]; $Rent = $_POST["Rent"]; $RentType = $_POST["RentType"]; $HouseType = $_POST["HouseType"]; //造連接對象 include("DBDA.class.php"); $db=new DBDA(); //寫sql語句 $sql="insert into house values(‘‘,‘{$KeyWord}‘,‘{$Area}‘,‘{$SquareMeter}‘,‘{$Rent}‘,‘{$RentType}‘,‘{$HouseType}‘)"; //執行語句 $r=$db->Query($sql,2);//($sql,2) 2代表增刪改 錯在了2上 if($r) { header("location:liebiaoyemian.php"); } else{ echo "執行失敗!"; } ?>
php租房題目