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" ...
随机推荐
- Struts2接受参数的几种类型和接受复杂类型参数(list<String>和list<Object>)
Struts2接受参数的几种类型 大概有这几种类型: 1.使用Action的属性接受参数 在Action中加入成员变量,配置Getter和Setter方法,Getter而和Setter方法的名字和表单 ...
- bzoj1468
1468: Tree Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1023 Solved: 532[Submit][Status][Discuss] ...
- 直播流怎么存储在Ceph对象存储上? Linux内存文件系统tmpfs(/dev/shm) 的应用
一./dev/shm理论 默认的Linux发行版中的内核配置都会开启tmpfs,映射到了/dev/下的shm目录.可以通过df 命令查看结果./dev/shm/是linux下一个非常有用的目录,因为这 ...
- HNU 13081 Even Up Solitaire解题报告
题目大意:给定一个数组,若相邻的两个数之和为偶数,则将此两个数移除,通过这种方法将满足条件得数移除后数组还剩多少个数. 此题太水,不做解释.直接代码之: #include <stdio.h> ...
- CSS控制之IE常见BUG及解决方案
常见bug 解决方案 盒模型bug 使用严格doctype声明 双倍margin bug _display:inline; 不认识a:link 不加:link 3像素margin bug 规范浮动与清 ...
- MySQL安装 MySQL5.7.10免安装版配置,mysql5.7.10免安装版
MySQL5.7.10免安装版配置,mysql5.7.10免安装版 最新版的 Mysql 不提供图形界面的安装了, 下载下来是一个压缩包的形式, 那么我们如何来使用它呢, 让它为我们工作呢? 环境: ...
- Git 的是使用入门
Coding 代码管理快速入门 当项目创建好了之后,我们该如何上传代码到 coding 上呢? Coding 网站使用“ Git 仓库”(类似 github )来管理代码. 其操作原理在于:利用 gi ...
- eclipse调试找不到源解决办法
eclipse调试时有时显示找不到源码,首先得确定代码没问题 这是eclipse没有发现工程源码,解决办法是 右键工程>>Debug As >> Debug configura ...
- js如何准确获取当前页面url网址信息
1.window.location.href(设置或获取整个 URL 为字符串) var test = window.location.href;alert(test);返回:http://i.cnb ...
- context.Session[“xxx”]详解
1.在aspx和aspx.cs中,都是以Session[“xxx”]=”aaa”和aaa=Session[“xxx”].ToString()进行读写.而在ashx中,Session都要使用contex ...