php封装+租房子练习题
第一个页面DBDA.class.php
<?php
class DBDA
{
public $host = "localhost";
public $uid = "root";
public $pwd = "root";
public $dbname = "dbname"; public function Query($sql,$type=1)//两个参数,第二个参数代表默认值
{
$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
$result = $db->query($sql); if($type=="1")//定义1类型的是查询,其它类型是增删改
{
return $result->fetch_all();
}else
{
return $result;
}
}
}
第二个页面main.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>
<form action="main.php" method="post">
<div>
<div>区域:<input type="checkbox" onclick="xuan(this,'qx')" />全选</div>//传入两个参数
<div>
<?php
include("./DBDA.class.php");//引入类文件
$db = new DBDA();
$sqx = "select distinct area from housedb";
$aqx = $db->Query($sqx); foreach($aqx as $v)
{
echo "<input type='checkbox' name='qx[]' class='qx' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
</div>
<br />
<div>
<div>租赁类型:<input type="checkbox" onclick="xuan(this,'zl')" />全选</div>
<div>
<?php
$szl = "select distinct renttype from housedb";
$azl = $db->Query($szl); foreach($azl as $v)
{
echo "<input type='checkbox' name='zl[]' class='zl' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
</div>
<br />
<div>
<div>房屋类型:<input type="checkbox" onclick="xuan(this,'fw')" />全选</div>
<div>
<?php
$sfw = "select distinct housetype from housedb";
$afw = $db->Query($sfw); foreach($afw as $v)
{
echo "<input type='checkbox' name='fw[]' class='fw' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
</div>
<br />
<div>关键字:<input type="text" name="keywords" />
<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 $tj1 = " 1=1 ";
$tj2 = " 1=1 ";
$tj3 = " 1=1 ";
$tj4 = " 1=1 "; if(!empty($_POST["qx"]) && count($_POST["qx"])>0)
{
$str = implode("','",$_POST["qx"]);
$tj1 = " area in ('{$str}') ";
}
if(!empty($_POST["zl"]) && count($_POST["zl"])>0)
{
$str = implode("','",$_POST["zl"]);
$tj2 = " renttype in ('{$str}') ";
}
if(!empty($_POST["fw"]) && count($_POST["fw"])>0)
{
$str = implode("','",$_POST["fw"]);
$tj3 = " housetype in ('{$str}') ";
}
if(!empty($_POST["keywords"]))
{
$key = $_POST["keywords"];
$tj4 = " keyword like '%{$key}%' ";
} $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">
function xuan(qx,lei)//方法类似的尽量写一个,改变参数
{
var ck = document.getElementsByClassName(lei);
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>
php封装+租房子练习题的更多相关文章
- php 租房子(练习题)
一.题目要求 1.功能描述 出租房屋数据管理及搜索页面 2.具体要求 (1) 创建数据库HouseDB,创建表House,要求如下: 二.题目做法 1.建立数据库 2.封装类文件 <?php ...
- 11月6日上午PHP练习《租房子》解析
一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...
- PHP-----练习-------租房子-----增删改查,多条件查询
练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...
- PHP实例练习--投票和租房子
一,调查问卷 效果图:
- php练习 租房子
题目要求 1.封装类 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming=&q ...
- 最近要租房子,用Python看一下房源吧..
前言:最近我的朋友想要租房子,为了装个b,决定运用技术去帮助他. 这个网站是什么我也不知道 反正是一个房子交易网站 http://www.ljia.net/ 设置请求头 headers = {'Ac ...
- PHP 练习(租房子)
一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...
- PHP 练习3:租房子
一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...
- 2016/3/30 租房子 ①建立租房子的增、删、改php页面 ②多条件查询 ③全选时 各部分全选中 任意checkbox不选中 全选checkbox不选中
字符串的另一种写法:<<<AAAA; 后两个AA回车要求顶格 不然报错 例子: <!DOCTYPE html> <html lang="en" ...
随机推荐
- bzoj1113
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1113 题解:单调栈 代码: #include<iostream> #includ ...
- freemarker配置,使用
最近在项目中用到freemarker,总是报一些莫名其妙的错误. 调查得知是由于在配置文件中属性[tag_syntax]的设置问题,我们的环境下该属性(auto_detect)默认设置了自动检测,也就 ...
- AngularJS中$http服务的简单用法
我们可以使用内置的$http服务直接同外部进行通信.$http服务只是简单的封装了浏览器原生的XMLHttpRequest对象. 1.链式调用 $http服务是只能接受一个参数的函数,这个参数是一个对 ...
- MySQL 替换部分电话号码为000
要做敏感信息剔除,要求又不能全换成同一个号码影响测试,想了几个方法,最终采用替换部分电话号码为000来做到敏感信息覆盖. mysql>update phone setb=replace(b,su ...
- win7如何安装mircosoft SDKs
WIN7不能安装SDK 7.1是因为系统程序里含Microsoft .NET Framework 4 Extended和Microsoft .NET Framework 4 Client Profil ...
- Flex移动应用程序开发的技巧和窍门(四)
范例文件 flex-mobile-dev-tips-tricks-pt4.zip 这是本系列文章的第四部分,该系列文章涵盖Flex移动开发的秘诀与窍门. 第一部分关注切换视图以及切换执行应用时的数据处 ...
- Paxos 实现日志复制同步
Paxos 实现日志复制同步 本篇文章以 John Ousterhout(斯坦福大学教授) 和 Diego Ongaro(斯坦福大学获得博士学位,Raft算法发明人) 在 Youtube 上的讲解视频 ...
- Bootstrap入门(十四)组件8:媒体对象
Bootstrap入门(十四)组件8:媒体对象 这是一个抽象的样式,用以构建不同类型的组件,这些组件都具有在文本内容的左或右侧对齐的图片(就像博客评论或 Twitter 消息等). 1.基本样式 2. ...
- iOS开发中@property的属性weak nonatomic strong readonly等介绍
@property与@synthesize是成对出现的,可以自动生成某个类成员变量的存取方法.在Xcode4.5以及以后的版本,@synthesize可以省略. 1.atomic与nonatomica ...
- linux 中用python实现终端命令行命令
在python代码中实现和在终端中输入的命令行一样的效果,以命令(audacious -p &)为例,该代码实现用audacious在后台播放音乐的功能,当然前提是安装了audacious. ...