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" ...
随机推荐
- 将MPLS编译进linux内核中
系统环境:linux kernel 2.6.35.(此环境是上一篇文章中将ubuntu内核替换后的环境) 编译过程如下: 1)首先需要下载patch文件:linux-kernel-v2.6.35-mp ...
- iOS 开源库介绍
1. Github-iOS备忘 2. iOS 第三方开源库的吐槽和备忘 3. 移动开发的后台服务支持平台 4. iOS 开源库 之 AFNetWorking 2.x 5. iOS 之 二维码 ZXin ...
- 全面解析Bootstrap图片轮播效果
http://www.jb51.net/article/75806.htm 一 . 结构分析 一个轮播图片主要包括三个部分: ☑ 轮播的图片 ☑ 轮播图片的计数器 ☑ 轮播图片的控制器 第一步:设计轮 ...
- 使用 StateServer 保存 Session 解决 Session过期,登陆过期问题。
使用 StateServer 保存 Session 正常操作情况下Session会无故丢失.因为程序是在不停的被操作,排除Session超时的可能.另外,Session超时时间被设定成60分钟,不会这 ...
- JS base64 加密和解密
/*** * 加密 base64encode(utf16to8(str)) * 解密 utf8to16(base64decode(str)) * * */ var base64EncodeChars ...
- 单选按钮(RadioButton)与复选框(CheckBox)的功能与用法
单选按钮(RadioButton)和复选框(CheckBox).状态开关按钮(ToggleButton)与开关(Switch)是用户界面中最普通的UI组件,他们都继承了Button类,因此都可直接使用 ...
- linux:基本命令
1.显示日期与时间:date 显示2009/08/17形式的格式:date +%Y/%m/%d 显示17:04时间格式:date +%H/%M 2.显示日历:cal 常用的命令:cal 2009:ca ...
- Node.js理解
JavaScript单线程的误解 在我接触JavaScript(无论浏览器还是NodeJS)的时间里,总是遇到有朋友有多线程的需求.而在NodeJS方面,有朋友甚至直接说到,NodeJS是单线程的,无 ...
- Android开发系列之事件拦截机制
对于Android开发者来说理解事件传递机制的重要性,我想应该是不言而喻的.在一个Activity里面,我们经常会重写onTouchEvent事件,可是重写结束之后,对于是返回true还是返回fals ...
- linux下读取系统内存的demo
#include <stdio.h> #define KIBIBYTE_SIZE 1024LL #define MEBIBYTE_SIZE 1048576LL #define GIBIBY ...