租房子 多条件查询

<!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="test.php" method="post">
	<div>区域:
    	<input type="checkbox" onclick="CheckAll(this,'qy')" />全选
    </div>
    <div>
    	<?php
		include("../DBDA.php");
		$db = new DBDA();
		
		$sqlqy = "select distinct Area from housedb";
		$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,'zl')" />全选
    </div>
    <div>
    	<?php
		$sqlzl = "select distinct RentType from housedb";
		$attrzl = $db->Query($sqlzl);
		
		foreach($attrzl as $v)
		{
			echo "<input class='zl' type='checkbox' value='{$v[0]}' name='zl[]' />{$v[0]} ";
		}
		
		?>
    </div><br />
    
    <div>房屋类型:
    	<input type="checkbox" onclick="CheckAll(this,'fw')" />全选
    </div>
    <div>
    	<?php
		$sqlfw = "select distinct HouseType from housedb";
		$attrfw = $db->Query($sqlfw);
		
		foreach($attrfw as $v)
		{
			echo "<input class='fw' type='checkbox' value='{$v[0]}' name='fw[]' />{$v[0]} ";
		}
		
		?>
    </div><br />
    
    <div>关键字:<input type="text" name="key" /></div>
    <br />
    <input type="submit" value="搜索" />

</form>
<br />

<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["qy"]))
{
	$attr = $_POST["qy"];
	$str = implode("','",$attr);
	
	$tj1 = " Area in ('{$str}')";
}

if(!empty($_POST["zl"]))
{
	$attr = $_POST["zl"];
	$str = implode("','",$attr);
	
	$tj2 = " RentType in ('{$str}')";
}

if(!empty($_POST["fw"]))
{
	$attr = $_POST["fw"];
	$str = implode("','",$attr);
	
	$tj3 = " HouseType in ('{$str}')";
}

if(!empty($_POST["key"]))
{
	$key = $_POST["key"];
	$tj4 = " KeyWord like '%{$key}%'";
}

$tj = " where {$tj1} and {$tj2} and {$tj3} and {$tj4}";


$sql = "select * from housedb".$tj;

$attrall = $db->Query($sql);

foreach($attrall 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,b)
{
	var xz = a.checked;//找到全选的选中状态
	var ck = document.getElementsByClassName(b);
	
	for(var i=0; i<ck.length;i++)
	{
		ck[i].checked = xz;
	}
}

</script>
</body>
</html>

  

原文地址:https://www.cnblogs.com/yuchao19950412/p/5501900.html