php 数据库练习之租房子
题目:

示例图


本次只做图4这个表,因为之前的都已做过
自己在mydb数据库建了一个house表
如图:


自己做的代码:
<!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>
<form action="house_main.php" method="post">
<div>
区域:
<input type="checkbox" name="qx1" onclick="checkall(this)" />全选
</div>
<div>
<?php
$db = new MySQLi("localhost","root","root","mydb");
$sqlqx = "select distinct area from house ";
$resultqx = $db->query($sqlqx);
while($arrqx = $resultqx->fetch_row())
{
echo"<input class='qx' type='checkbox' value='{$arrqx[0]}' name='qx[]' />{$arrqx[0]}";
}
?>
</div>
<div>
租赁类型:
<input type="checkbox" name="qx2" onclick="checkall2(this)"/>全选
</div>
<div>
<?php
$sqlqy = "select distinct renttype from house ";
$resultqy = $db->query($sqlqy);
while($arrqy = $resultqy->fetch_row())
{
echo"<input class='qy' type='checkbox' value='{$arrqy[0]}' name='qy[]'/>{$arrqy[0]}";
}
?> </div> <div>
房屋类型:
<input type="checkbox" name="qx3" onclick="checkall3(this)"/>全选
</div>
<div>
<?php
$sqlqz = "select distinct housetype from house";
$resultqz = $db->query($sqlqz);
while($arrqz = $resultqz->fetch_row())
{
echo"<input class='qz' type='checkbox' value='{$arrqz[0]}' name='qz[]' />{$arrqz[0]}";
}
?>
</div> <div>
关键字:
<input type="text" name="keyword"/>
</form>
<br /> <input type="submit" value="搜索" />
</div> </div>
<br />
<br />
<br /> </form>
<table width="50%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>关键字</td>
<td>区域</td>
<td>建筑面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
</tr>
<?php
$tj = "";
$tj1 = "1=1";
$tj2 = "2=2";
$tj3 = "3=3";
$tj4 = "4=4";
if(!empty($_POST["qx"]) && count($_POST["qx"]>0))
{
$attr = $_POST["qx"];
$str = implode("','",$attr); $tj1 = "area in ('{$str}')";
}
if(!empty($_POST["qy"]) && count($_POST["qy"]>0))
{
$attr = $_POST["qy"];
$str = implode("','",$attr);
$tj2 = "renttype in ('{$str}')";
}
if(!empty($_POST["qz"]) && count($_POST["qz"]>0))
{
$attr = $_POST["qz"];
$str = implode("','",$attr); $tj3 = "housetype in ('{$str}')";
}
if(!empty($_POST["keyword"]) && count($_POST["keyword"]>0))
{
$attr = $_POST["keyword"];
$tj4 = "keyword like '%{$attr}%'";
}
//$tj = " where {$tj1} and {$tj2} and {$tj3} and {$tj4} ";
$sql = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4} ";
$attry = $db->query($sql);
while($arr = $attry->fetch_row())
{
echo"<tr>
<td>{$arr[1]}</td>
<td>{$arr[2]}</td>
<td>{$arr[3]}</td>
<td>{$arr[4]}</td>
<td>{$arr[5]}</td>
<td>{$arr[6]}</td>
</tr>";
}
?> </table>
</body>
</html>
<script type="text/javascript"> function checkall(qx)
{ //ck变量不能重复设置
var ck = document.getElementsByClassName("qx");
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");
}
}
}
function checkall2(qy)
{
var ck2 = document.getElementsByClassName("qy");
if(qy.checked)
{
for(var i=0;i<ck2.length;i++)
{
ck2[i].setAttribute("checked","checked");
}
}
else
{
for(var i=0;i<ck2.length;i++)
{
ck2[i].removeAttribute("checked");
}
}
}
function checkall3(qz)
{
var ck3 = document.getElementsByClassName("qz");
if(qz.checked)
{
for(var i=0;i<ck3.length;i++)
{
ck3[i].setAttribute("checked","checked");
}
}
else
{
for(var i=0;i<ck3.length;i++)
{
ck3[i].removeAttribute("checked");
}
}
}
</script>
展示效果:

查询范例:

搜索结果如下:

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.功能描述 出租房屋数据管理及搜索页面 2.具体要求 (1) 创建数据库HouseDB,创建表House,要求如下: 二.题目做法 1.建立数据库 2.封装类文件 <?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 ...
- php封装+租房子练习题
第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = " ...
随机推荐
- jQuery或者js保存文件到本地
一: // 浏览文件夹(指定文件路径) function BrowseFolder() { try { var Message = "Please select the folder pat ...
- 启动haoop并运行wordcount
启动hadoop,这里hadoop的版本是2.7.4 进入Hadoop的安装目录的bin目录下,采用-format命令格式化文件系统. hadoop namenode -format hadoop d ...
- C#操作摄像头 实现拍照功能
从正式工作以来一直做的都是基于B/S的Web开发,已经很长时间不研究C/S的东西了,但是受朋友的委托,帮他做一下拍照的这么个小功能.其实类似的代码网上有很多,但是真的能够拿来运行的估计也没几个.本来是 ...
- win10计算机打开不要是“快速访问”功能?
win10的文件夹选项中---常规--最上端调整
- WPF教程一:基础
一.WPF简介WPF:WPF即Windows Presentation Foundation,翻译为中文“Windows呈现基础”,是微软推出的基于Windows Vista的用户界面框架,属于.NE ...
- rails中render 和 redirect_to的区别, each只能用在数组中,如果只有一个或者零个项,用each方法会报错undefined method `each' for #...
在render中,即使有:action,那么也仅仅是取对应的view中的模板(html.erb)而已,所以这里即使浏览器中的url是/orders/xcreate,但是显示的界面是/app/views ...
- Jquery同时绑定多个事件
//JQ 同时绑定多个事件 $("div.div_grren a img").bind({ mouseover:function(){ $(this).attr('src',bor ...
- Linux之zip压缩
1.压缩 对于test目录,使用 zip -rq test.zip test r表示递归压缩,q表示不显示过程 2.解压缩 unzip -q test.zip
- Spring 4 官方文档学习(十)数据访问之OXM
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html Java Object 与 XML ...
- (转)sqlite3生成lib遇到的问题
今天想用一用sqlite,但是下载后发现只有DLL,没有LIB,只能自己生成了.在H:/Program Files/Microsoft Visual Studio 8/VC/bin里面有个lib.ex ...