一、题目要求

二、题目做法

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>

PHP 练习3:租房子的更多相关文章

  1. 11月6日上午PHP练习《租房子》解析

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  2. PHP-----练习-------租房子-----增删改查,多条件查询

    练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...

  3. PHP实例练习--投票和租房子

    一,调查问卷 效果图:

  4. php 租房子(练习题)

    一.题目要求 1.功能描述   出租房屋数据管理及搜索页面 2.具体要求 (1) 创建数据库HouseDB,创建表House,要求如下: 二.题目做法 1.建立数据库 2.封装类文件 <?php ...

  5. php封装+租房子练习题

    第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = " ...

  6. php练习 租房子

    题目要求 1.封装类 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming=&q ...

  7. 最近要租房子,用Python看一下房源吧..

    前言:最近我的朋友想要租房子,为了装个b,决定运用技术去帮助他. 这个网站是什么我也不知道 反正是一个房子交易网站  http://www.ljia.net/ 设置请求头 headers = {'Ac ...

  8. PHP 练习(租房子)

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  9. 2016/3/30 租房子 ①建立租房子的增、删、改php页面 ②多条件查询 ③全选时 各部分全选中 任意checkbox不选中 全选checkbox不选中

    字符串的另一种写法:<<<AAAA; 后两个AA回车要求顶格  不然报错 例子: <!DOCTYPE html> <html lang="en" ...

随机推荐

  1. [solution]xdebug正确配置,但不显示错误信息

    一开始以为是配置问题,其实不是,折腾了好久,貌似中文网页很少有人提到这事,更别提解决之道! 最好还是用英文关键词google之:得如下网页 https://bugs.launchpad.net/ubu ...

  2. LintCode-71.二叉树的锯齿形层次遍历

    二叉树的锯齿形层次遍历 给出一棵二叉树,返回其节点值的锯齿形层次遍历(先从左往右,下一层再从右往左,层与层之间交替进行) 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, 返回其锯齿形的层次 ...

  3. ZOJ 1666 G-Square Coins

    https://vjudge.net/contest/67836#problem/G People in Silverland use square coins. Not only they have ...

  4. 使用LoadRunner脚本采集Linux性能数据

    前面介绍过在LoadRunner的Java协议实现“使用SSH连接Linux”.下面的脚本,是在LoadRunner里连接Linux/Unix远程服务器,收集其磁盘IO的负载到测试结果. 涉及到三个知 ...

  5. WIN7使用过360系统急救箱后出现的任务计划程序文件夹删除的办法

    直接进主题(怀疑系统有问题用了下360系统急救箱,用完后发现计划任务多了个360superkiller文件夹,右键直接是删除不了的) 尝试了各种方法都是不爽,突然想到计划任务不是在在系统盘下的一个文件 ...

  6. str.substring(beginIndex,endIndex)-008

    // 将字符串str前n位放在后面,返回新的字符串 public String headToTail(String str,int n){ if(n==0){ System.out.println(s ...

  7. linux下清空文件全部内容,如log日志

    在实际操作中经常需要清空log文件, 比如a.log,   有的人说, 直接删除不就行了, 但是, 直接删除后, 没法使用tail -f a.log了. 有的人说, 先rm再touch一个新文件不就可 ...

  8. 【bzoj1775】[Usaco2009 Dec]Vidgame 电视游戏问题 dp

    题目描述 输入 * 第1行: 两个由空格隔开的整数: N和V * 第2到第N+1行: 第i+1行表示第i种游戏平台的价格和可以在这种游戏平台上面运行的游 戏.包含: P_i, G_i还有G_i对由空格 ...

  9. Devc++编译系统分配给int多少字节

    我看的是<C语言程序设计>..谭浩强的PDF版 里面只讲了VC和TC 的,没有Devc++的..(我的是5.10版) 还有这是什么意思? 经过查阅我进行了这样的测试: 得到了这样的结果: ...

  10. python 中的queue 与多进程--待继续

    一.先说说Queue(队列对象) Queue是python中的标准库,可以直接import 引用,之前学习的时候有听过著名的“先吃先拉”与“后吃先吐”,其实就是这里说的队列,队列的构造的时候可以定义它 ...