PHP制作查询租房表

时间:2023-12-04 16:20:44
 <!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>

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" 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>
图一,图二是运行区域全选的功能

图一PHP制作查询租房表图2PHP制作查询租房表