码迷,mamicode.com
首页 > Web开发 > 详细

PHP租房子练习

时间:2016-06-21 12:37:41      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

租房查询

<!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="zufangchaxun.php" method="post">
<div>区域:<input type="checkbox" onclick="CheckAll(this,‘qy‘)"/>全选</div>
<div>
<?php
include("DBDA.class.php");
$db=new DBDA();
$sqlqy="select distinct Area from house";//distinct去重
$attrqy=$db->Query($sqlqy);
foreach($attrqy as $v)
{
	echo "<input class=‘qy‘ type=‘checkbox‘ value=‘{$v[0]}‘ name=‘qy[]‘/>$v[0] ";
}
?>
</div><br />
<div>租赁类型:<input type="checkbox" onclick="CheckAll(this,‘zllx‘)"/>全选</div>
<div>
<?php
$sqlzllx="select distinct RentType from house";
$attrzllx=$db->Query($sqlzllx);
foreach($attrzllx as $v)
{
	echo "<input class=‘zllx‘ type=‘checkbox‘ value=‘{$v[0]}‘ name=‘zllx[]‘/>$v[0] ";
}
?>
</div><br />
<div>房屋类型:<input type="checkbox" onclick="CheckAll(this,‘fwlx‘)"/>全选</div>
<div>
<?php
$sqlfwlx="select distinct HouseType from house";
$attrfwlx=$db->Query($sqlfwlx);
foreach($attrfwlx as $v)
{
	echo "<input class=‘fwlx‘ type=‘checkbox‘ value=‘{$v[0]}‘ name=‘fwlx[]‘/>$v[0] ";
}
?>
</div><br />
<div>关键字:<input type="text" name="key"/></div><input type="submit" value="搜索"/>
</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))
{
	if(!empty($_POST["qy"]))
	{
		$str1=implode("‘,‘",$_POST["qy"]);
		$tj1="Area in (‘{$str1}‘)";
	}
	if(!empty($_POST["zllx"]))
	{
		$str2=implode("‘,‘",$_POST["zllx"]);
		$tj2="RentType in (‘{$str2}‘)";
	}
	if(!empty($_POST["fwlx"]))
	{
		$str3=implode("‘,‘",$_POST["fwlx"]);
		$tj3="HouseType in (‘{$str3}‘)";
	}
	if($_POST["key"]!="")
	{
		$tj4="KeyWord like ‘%{$_POST[‘key‘]}%‘";
	}	
}
//总条件
$ztj=" where ($tj1) and ($tj2) and ($tj3) and ($tj4)";
$sql="select * from house".$ztj;
echo $sql;
$attr=$db->Query($sql);
foreach($attr 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 CheckAll(a,b)
{
	var ck=document.getElementsByClassName(b);
	for(var i=0;i<ck.length;i++)
	{
		if(a.checked)
		{
			ck[i].setAttribute("checked",‘checked‘);
		}
		else
		{
			ck[i].removeAttribute("checked");
		}
	}
}
</script>
</html>

  

PHP租房子练习

标签:

原文地址:http://www.cnblogs.com/hamilton/p/5602956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!