一、题目要求

二、题目做法

1.建立数据库

2.封装类文件

<?php
class DBDA
{
public $fuwuqi="localhost"; //服务器地址
public $yonghuming="root";//用户名
public $mima="";//密码
public $dbconnect;//连接对象
//操作数据库的方法 //$sql代表需要执行的SQL语句
//$type代表SQL语句的类型,1代表查询,2代表增删改
//$shujukuming代表数据库的名称
//如果是查询,返回二维数组
//如果是增删改,返回true或false function Query($sql,$type=1,$shujukuming="house")
{
//造连接对象
$this->dbconnect = new MySQLi($this->fuwuqi,$this->yonghuming,$this->mima,$shujukuming); //判断是否出错
if(!mysqli_connect_error())
{
//如果连接成功,执行SQL语句
$result = $this->dbconnect->query($sql); //根据语句类型判断
if($type==1)
{
//如果是查询语句,返回二维数组
return $result->fetch_all();
}
else
{
//如果是其他语句,返回true或false
return $result;
} }
else
{
return"连接失败";
}
}
}
?>

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 "执行失败!";
}
?>

9.搜索页面(多条件查询)

<!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> <body>
<form action="duotiaojianchaxun.php" method="post">
<div>区域:<input type="checkbox" onclick="CheckAll(this,'qy')" />全选</div>
<div> <?php
include("DBDA.class.php");
$db = new DBDA(); $sqlqy = "select distinct Area from house";
$attrqy = $db->Query($sqlqy);
//var_dump($attrqy); foreach($attrqy as $v)
{
echo "<input class='qy' type='checkbox' value='{$v[0]}' name='qy[]'/>{$v[0]} ";
}
?> </div><br /> <div>租赁类型:<input type="checkbox" onclick="CheckAll(this,'zl')" />全选</div>
<div> <?php $sqlzl = "select distinct RentType from House";
$attrzl = $db->Query($sqlzl); foreach($attrzl as $v)
{
echo "<input class='zl' type='checkbox' value='{$v[0]}' name='zl[]'/>{$v[0]} ";
}
?> </div><br /> <div>房屋类型:<input type="checkbox" onclick="CheckAll(this,'fw')" />全选</div>
<div> <?php $sqlfw = "select distinct HouseType from House";
$attrfw = $db->Query($sqlfw);
//var_dump($attrqy); foreach($attrfw as $v)
{
echo "<input class='fw' type='checkbox' value='{$v[0]}' name='fw[]'/>{$v[0]} ";
}
?> </div><br /> <div>关键字:<input type="text" name="keyword" id="key" />
</form>
<br />
<input type="submit" value="搜索" /> <br />
<br />
<br /> <table cellpadding="1" cellspacing="1" border="1" width="100%">
<tr>
<td>关键字</td>
<td>区域</td>
<td>面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
</tr>
<?php

$tj = "";
$tj1 = "1=1";
$tj2 = "1=1";
$tj3 = "1=1";
$tj4 = "1=1"; if(!empty($_POST["qy"]))
{
$attr = $_POST["qy"];
$str = implode("','",$attr);
$tj1 = " Area in ('{$str}')";
} if(!empty($_POST["zl"]))
{
$attr = $_POST["zl"];
$str = implode("','",$attr);
$tj2 = " RentType in ('{$str}')";
} if(!empty($_POST["fw"]))
{
$attr = $_POST["fw"];
$str = implode("','",$attr);
$tj3 = " HouseType in ('{$str}')";
} if(!empty($_POST["keyword"]))
{
$attr = $_POST["keyword"];
$tj3 = " keyword like '%{$attr}%'";
} $tj = " Where {$tj1} and {$tj2} and {$tj3} and {$tj4}";//Where 前加空格 $sql = "select * from House".$tj;
$attrall = $db->Query($sql);
//var_dump($attrall); foreach($attrall 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 CheckAll(a,b)//this表示该
{
var qx = a.checked;
var ck = document.getElementsByClassName(b);
for(var i =0;i<ck.length;i++)
{
ck[i].checked = qx;
}
} </script> </html>
</body>
</html>

11月6日上午PHP练习《租房子》解析的更多相关文章

  1. 11月13日上午ajax返回数据类型为JSON数据的处理

    ajax返回数据类型为JSON数据的处理 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...

  2. 11月10日上午ajax基础知识、用ajax做登录页面、用ajax验证用户名是否可用、ajax动态调用数据库

    1.ajax的基础知识 ajax是结合了jquery.php等几种技术延伸出来的综合运用的技术,不是新的内容.ajax也是写在<script>标签里面的. 如果使用ajax一定是要有1个处 ...

  3. 11月8日上午Jquery的基础语法、选取元素、操作元素、加事件、挂事件及移除事件

    jquery基础知识 1.jquery文件的引入,所有的js代码要写在下面那段代码下面. <script src="../jquery-1.11.2.min.js">& ...

  4. 11月7日上午PHP会话控制(session和cookie)、跨页面传值

    1.session  登录上一个页面以后,长时间没有操作,刷新页面以后需要重新登录. 特点:(1)session是存储在服务器:   (2)session每个人(登陆者)存一份: (3)session ...

  5. 11月3日上午PHP练习《投票》

    1.建立数据库 表1:DiaoYanTiMu 表2:DiaoYanXuanXiang 2.页面 页面1:投票首页 <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  6. 11月1日上午PHP------empty、 is_null、isset、unset的区别

    1.empty 判断一个变量是否为"空".null.false.00.0.'0′.』.为以上值的变量在检测時都将返回true. 2.isset 判断一个变量是否已经设置.0.00. ...

  7. 11月1日上午PHP批量删除

    1.在主页面上添加批量删除有关代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  8. 11月30日《奥威Power-BI智能分析报表制作方法》腾讯课堂开课啦

    这么快一周就过去了,奥威公开课又要与大家见面咯,上节课老师教的三种报表集成方法你们都掌握了吗?大家都知道,学习的结果在于实际应用,想要熟练掌握新内容的要点就在于去应用它.正是基于这一要点,每一期的课程 ...

  9. 11月23日《奥威Power-BI报表集成到其他系统》腾讯课堂开课啦

    听说明天全国各地区都要冷到爆了,要是天气冷到可以放假就好了.想象一下大冷天的一定要在被窝里度过才对嘛,索性明天晚上来个相约吧,相约在被窝里看奥威Power-BI公开课如何?        上周奥威公开 ...

随机推荐

  1. web.xml is missing and <failOnMissingWebXml> is set to true 错误解决办法

    对web项目的解决方案: 右击项目——>Java EE Tools——>Generate Deployment Descriptor Stub. 然后系统会在src/main/webapp ...

  2. ligerDialog的使用

    1.通过ViewBag来传值. @if (ViewBag.ReturnMessage != null) 2.脚本代码: 对话框设计与赋值问题. <script type="text/j ...

  3. Win Server 2008 RD案例:Client通过Server的浏览器上网

    一.简介 RD是Windows Server远程桌面服务,可以实现从客户端运行服务器上的软件.首先在Server安装软件,设置能远程访问的应用和账号,并且创建.rdp快捷方式文件,然后Client打开 ...

  4. LLVM 笔记(四)—— three-phase 设计的收益

    ilocker:关注 Android 安全(新手) QQ: 2597294287 采用 three-phase 的设计方式,便于编译器支持多种语言和多种目标平台. 如果在优化器阶段采用通用的 IR ( ...

  5. linux下使用denyhosts防止ssh暴力破解

    1.DenyHosts介绍 DenyHosts是Python语言写的一个程序,它会分析sshd的日志文件(/var/log/secure),当发现重 复的攻击时就会记录IP到/etc/hosts.de ...

  6. CSS控制TD内的文本超出指定宽度后不换行而用省略号代替

    <style type="text/css"> .lineOverflow { width: 100px; border:#000 solid 1px; text-ov ...

  7. NopCommerce 增加 Customer Field

    预期效果: Customer表新增一个Column 该新增字段可以在Admin段 新增 修改 列表查询及显示 示例步骤: 0.数据库表修改 alter table [Customer] add Mem ...

  8. Android开发资源汇总

    搜索 虫部落快搜(已被墙) Google免FQ镜像汇总 Lantern stackoverflow 博客 Android基础&进阶 深入理解Android 老罗的Android之旅 Andro ...

  9. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  10. POJ1061青蛙的约会[扩展欧几里得]

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 108911   Accepted: 21866 Descript ...