php租房题目
Posted palpitate
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php租房题目相关的知识,希望对你有一定的参考价值。
<!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租房题目的主要内容,如果未能解决你的问题,请参考以下文章