<form action=" chaxun.php" method="post" >
<div>区域:<input type="checkbox" onclick="quanxuan(this)" name="mb[]"/>全选</div>
<?php
$db=new MySQLi("localhost","root","123","test");
//查区域
$spl="select quyu from house";
$resul=$db->query($spl);
$att=$resul->fetch_all();
//显示区域向右流
foreach($att as $v)
{
echo "<div style='float:left'><input type='checkbox' name='mz[]' value={$v[0]} class='mz' />{$v[0]}</div>";
}
?>
<br />
<div>使用面积<input type="checkbox" onclick="quanxua(this)" />全选</div>
<?php
//去重差面积
$sol= "select distinct mianji from house";
$resu=$db->query($sol);
$at=$resu->fetch_all();
foreach($at as $v)
{
echo "<div style='float:left'><input type='checkbox' name='ma[]' value={$v[0]} class='ma' />{$v[0]}</div>";
}
?>
<br />
<div>关键字:<input type="text" name="xm" /></div>
<input type="submit" value="查询" />
</form>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td></td>
<td>关键字</td>
<td>区域</td>
<td>使用面积</td>
<td>租金</td>
<td>租聘类型</td>
<td>房屋类型</td>
</tr>
<?php
$xxm= "";
$cj1 = " 1=1 ";
$cj2 = " 1=1 ";
$cj3 = " 1=1 ";
//判断值数组值
$mz=array();
if(!empty($_POST["mz"]) && $_POST["mz"]!="")
{
$mz=$_POST["mz"];
$a=implode("','",$mz);
$cj2=" quyu in ('{$a}')";
}
$ma=array();
if(!empty($_POST["ma"])&& $_POST["ma"]!="")
{
$ma=$_POST["ma"];
$m=implode("','",$ma);
$cj3=" mianji in ('{$m}')";
}
//关键字查询
if(!empty( $_POST["xm"] )&& $_POST["xm"]!="")
{
$xxm=$_POST["xm"];
$cj1="guaniazi like '%{$xxm}%'";
}
//写sql语句
$sql="select*from house where ".$cj1. " and " .$cj2. "and" .$cj3;
//echo $sql;
$resule=$db->query($sql);
$attr=$resule->fetch_all();
foreach($attr as $v)
{
//输出关键字
$name=str_replace($xxm,"<mark>{$xxm}</mark>",$v[1]);
echo "<tr>";
echo"<td><a href='xiugai.php?c={$v[0]}'>修改</a> <a href='shanchu.php?c={$v[0]}' onclick=\"return confirm('删除吗')\">删除</a></td><td>{$name}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td><td>{$v[5]}</td><td>{$v[6]}</td>";
echo "</tr>";
}
?>
</table>
<a href="tianjia.php"><input type="submit" value="添加新数据" /></a>
<script type="text/javascript">
//判断全选
function quanxuan(a)
{
var attw=document.getElementsByClassName("mz");
for(i=0;i<attw.length;i++)
{
if(a.checked)
{
attw[i].setAttribute("checked","checked");
}
else
{
attw[i].removeAttribute("checked");
}
}
}
function quanxua(b)
{
var att=document.getElementsByClassName("ma");
for(i=0;i<att.length;i++)
{
if(b.checked)
{
att[i].setAttribute("checked","checked");
}
else
{
att[i].removeAttribute("checked");
}
}
}
</script>