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> <!--<textarea style=" overflow: scroll;"></textarea>文本域-->
<!--当我点击查询的时候会把数据传到当前页面,提交到当前页面-->
<?php
$db = new MySQLi("localhost","root","511108","text");
//在这个页面就能把提交的数据放到这是用了
//做查询的时候传递过来几条数据就就做几个条件
$tj1 = " 1=1 ";
$tj2 = " 1=1 ";
$tj3 = " 1=1 ";
$tj4 = " 1=1 "; //区域的条件
//var_dump($_POST["qx"]);//测试输出用
if(!empty($_POST["qx"]) && count($_POST["qx"])>0)//判断countyaodayu零如果等于零还是查所有
{
//$tj1 = "";
$qx = $_POST["qx"];//这是一个数组把数组要转化字符串
//select * from info where code in('类型','数量','','','')//数组里面每个元素就是一个值。如何拼成字符串:用拆分字符串implode方法(','拼接)
$str = implode("','",$qx);
//echo $str;//输出
$tj1 = " area in('{$str}') ";//完整的条件
//echo $tj1;//输出看看tj1 是不是完整条件
}
//租赁类型的条件
if(!empty($_POST["zl"]) && count($_POST["zl"])>0)
{
$zl = $_POST["zl"];
$str = implode("','",$zl);
$tj2 = " renttype in('{$str}') ";
}
//房屋类型的条件
if(!empty($_POST["fw"]) && count($_POST["fw"])>0)
{
$fw = $_POST["fw"];
$str = implode("','",$fw);
$tj3 = " housetype in('{$str}') ";
//echo $tj3; //测试输出
}
//关键字的条件
if(!empty($_POST["key"]))
{
$key = $_POST["key"];//把$_POST["key"]交给$key变量
$tj4 = " keyword like '%{$key}%' ";//不为空就变成关键字模糊查询,把$key变量拿过来
} ?> <h1>租房</h1>
<form action="fangwu12.php" method="post">
<div>
区域:
<input type="checkbox" name="qx" />全选
</div>
<div>
<?php
$sqlq = "select distinct area from house";//去重distinct
$rq = $db->query($sqlq);
$aq = $rq->fetch_all();
foreach($aq as $v)//循环输出
{
echo "<input type='checkbox' name='qx[]' value='{$v[0]}' />{$v[0]}";// name='qx[]'以数组形式提交
}
?>
</div>
<br/> <div>
租赁类型:
<input type="checkbox" name="qx" />全选</div>
<div>
<?php
$sqlz = "select distinct renttype from house";//去重distinct
$rz = $db->query($sqlz);
$az = $rz->fetch_all();
foreach($az as $v)//循环输出
{
echo "<input type='checkbox' name='zl[]' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
<br/> <div>
房屋类型:
<input type="checkbox" name="qx" />全选</div>
<div>
<?php
$sqlf = "select distinct housetype from house";//去重distinct
$rf = $db->query($sqlf);
$af = $rf->fetch_all();
foreach($af as $v)//循环输出
{
echo "<input type='checkbox' name='fw[]' value='{$v[0]}' />{$v[0]} ";
}
?>
</div>
<br/>
<div>
关键字:
<input type="text" name="key" />
<input type="submit" value="查询" />
</div>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>关键字</td>
<td>区域</td>
<td>建筑面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
</tr>
<?php
$sqlall = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
//echo $sqlall;//什么也不选就是默认所有
$rall = $db->query($sqlall);
$aall = $rall->fetch_all();
foreach($aall 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>
</html>

<!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> <!--<textarea style=" overflow: scroll;"></textarea>文本域-->
<!--当我点击查询的时候会把数据传到当前页面,提交到当前页面-->
<?php
$db = new MySQLi("localhost","root","511108","text");
//在这个页面就能把提交的数据放到这是用了
//做查询的时候传递过来几条数据就就做几个条件
$tj1 = " 1=1 ";
$tj2 = " 1=1 ";
$tj3 = " 1=1 ";
$tj4 = " 1=1 "; //区域的条件
//var_dump($_POST["qx"]);//测试输出用
if(!empty($_POST["qx"]) && count($_POST["qx"])>0)//判断countyaodayu零如果等于零还是查所有
{
//$tj1 = "";
$qx = $_POST["qx"];//这是一个数组把数组要转化字符串
//select * from info where code in('类型','数量','','','')//数组里面每个元素就是一个值。如何拼成字符串:用拆分字符串implode方法(','拼接)
$str = implode("','",$qx);
//echo $str;//输出
$tj1 = " area in('{$str}') ";//完整的条件
//echo $tj1;//输出看看tj1 是不是完整条件
}
//租赁类型的条件
if(!empty($_POST["zl"]) && count($_POST["zl"])>0)
{
$zl = $_POST["zl"];
$str = implode("','",$zl);
$tj2 = " renttype in('{$str}') ";
}
//房屋类型的条件
if(!empty($_POST["fw"]) && count($_POST["fw"])>0)
{
$fw = $_POST["fw"];
$str = implode("','",$fw);
$tj3 = " housetype in('{$str}') ";
//echo $tj3; //测试输出
}
//关键字的条件
if(!empty($_POST["key"]))
{
$key = $_POST["key"];//把$_POST["key"]交给$key变量
$tj4 = " keyword like '%{$key}%' ";//不为空就变成关键字模糊查询,把$key变量拿过来
} ?> <h1>租房</h1>
<form action="fangwu12.php" method="post">
<div>
区域:
<input type="checkbox" onclick="checkall(this)" />全选
</div>
<div>
<?php
$sqlq = "select distinct area from house";//去重distinct
$rq = $db->query($sqlq);
$aq = $rq->fetch_all();
foreach($aq as $v)//循环输出
{
echo "<input type='checkbox' name='qx[]' value='{$v[0]}' class='qxlist' />{$v[0]}";// name='qx[]'以数组形式提交
}
?>
</div>
<br/> <div>
租赁类型:
<input type="checkbox" name="qx" />全选</div>
<div>
<?php
$sqlz = "select distinct renttype from house";//去重distinct
$rz = $db->query($sqlz);
$az = $rz->fetch_all();
foreach($az as $v)//循环输出
{
echo "<input type='checkbox' name='zl[]' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
<br/> <div>
房屋类型:
<input type="checkbox" name="qx" />全选</div>
<div>
<?php
$sqlf = "select distinct housetype from house";//去重distinct
$rf = $db->query($sqlf);
$af = $rf->fetch_all();
foreach($af as $v)//循环输出
{
echo "<input type='checkbox' name='fw[]' value='{$v[0]}' />{$v[0]} ";
}
?>
</div>
<br/>
<div>
关键字:
<input type="text" name="key" />
<input type="submit" value="查询" />
</div>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>关键字</td>
<td>区域</td>
<td>建筑面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
</tr>
<?php
$sqlall = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
//echo $sqlall;//什么也不选就是默认所有
$rall = $db->query($sqlall);
$aall = $rall->fetch_all();
foreach($aall 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>
<!--下是控制区域全选,上面有个区域-->
<script type="text/javascript"> function checkall(a)
{
var ck = document.getElementsByClassName("qxlist");
<!--document.getElementById().setAttribute()用来设置属性的-->
if(a.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> </body>
</html>
图一,图二是运行区域全选的功能
图一
图2
PHP制作查询租房表的更多相关文章
- 利用Bootstrap框架制作查询页面的界面
UI设计实战篇——利用Bootstrap框架制作查询页面的界面 Bootstrap框架是一个前端UI设计的框架,它提供了统一的UI界面,简化了设计界面UI的过程(缺点是定制了界面,调整的余地不是太 ...
- myql 查询树形表结果:说说、说说的述评、评论的回复
myql 查询树形表结果:说说.说说的评论.评论的回复 有三张表关联表: 用户的说说表(ixt_customer_note) 说说的评论表(ixt_customer_note_comment) 评论的 ...
- sql查询指定表外键约束
//////////////////查询指定表外键约束select a.name as 约束名, object_name(b.parent_object_id) as 外键表, d.name as 外 ...
- SQL查询每个表的字段数量
--SQL查询每个表的字段数量select b.[name], count(*) As AllCount,ISNULL(ISNULL(sum(case when isnullable=0 then 1 ...
- SQL server 查询某个表在哪些存储过程(SP)中使用到
1.查询某个表被哪些存储过程(以下简称 SP)使用到 : select distinct object_name(id) from syscomments where id in (select ob ...
- SQL 查询所有表名、字段名、类型、长度、存储过程、视图
-- 获得存储过程创建语句 select o.xtype,o.name,cm.text from syscomments cm inner join sysobjects o on o.id=cm.i ...
- 【转】oracle查询用户表,函数,储存过程,
◆Oracle查询用户表空间:select * from user_all_tables ◆Oracle查询所有函数和储存过程:select * from user_source ◆Oracle查询所 ...
- SQL语句查询某表的所有字段及数据类型
SQL语句查询某表的所有字段及数据类型 SELECT name AS column_name , TYPE_NAME(system_type_id) AS column_type , max_leng ...
- sqlserver查询所有表名、字段名、类型、长度和存储过程、视图的创建语句
-- 获得存储过程创建语句 select o.xtype,o.name,cm.text from syscomments cm inner join sysobjects o on o.id=cm.i ...
随机推荐
- 分享篇——我的Java学习路线
虽然之前我是开发出身,但是我学习的语言是Objective-c,这个语言使用起来范围比较窄,对于自动化学习来说也是无用武之地,所以我自己学习了Java,对于一个有开发经验的人来说学习一门新语言相对来说 ...
- Vue - 自定义指令
1.Vue.directive(id,definition)注册一个全局自定义指令,接收两个参数,指令ID以及定义对象 2.钩子函数:将作用域与DOM进行链接,链接函数用来创建可以操作DOM的指令 b ...
- LeetCode 389. Find the Difference
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- iOS Real Stuff
Ray Wenderlich AppCoda(English) AppCoda(TW) Awesome iOS Code4App代码库 CocoaChina代码库 o ...
- T-SQL Recipes之Common Function
在我们写SQL的时候,经常会用到许多内置方法,简化了我们许多代码,也提高了效率,这篇主要总结一些常用的方法. ISNULL VS COALESCE VS NULLIF 在SQL中,NULL值是比较特殊 ...
- NOIP2016普及
还记得去年局部变量忘记置零coin爆零的事......结果我今年又要考一年普及[趴 最近沉迷分块莫队无法自拔,这几天才想起来我是个普及组选手 几乎没准备普及,周六上午抱抱佛脚好了...... 希望能顺 ...
- Unity中的Matrix4x4类
物体平移旋转一般变换底层都是用矩阵来表示的,一般不会用到这个类.有时候需要一些世界坐标与局部坐标转换的时候,可能就要用到了. //创建平移 旋转 缩放矩阵 可以理解为一个坐标系(不知道对不对..) M ...
- 【BZOJ1497】[NOI2006]最大获利 最小割
裸的最小割,很经典的模型. 建图:要求总收益-总成本最大,那么将每条弧与源点相连,流量为成本,每个收益与汇点相连,流量为收益,然后每条弧与它所能到达的收益相连,流量为inf. 与源点相连的是未被选中的 ...
- 《一个操作系统的实现》学习笔记(一) bochs源码安装及配置
前言:本机环境ubuntu 14.04 bochs 2.4.5 一.下载 官网 http://bochs.sourceforge.net/ 二.安装 1.将下载好的压缩包解压并进入该目录 .tar.g ...
- thinkphp 缓存数据
thinkphp 中内置了缓存操作 3.1版本的数据缓存方法是cache 基本用法: S(array('type'=>'xcache','expire'=>60)); 缓存初始化 缓存初始 ...