复选框式查询 例题租房子

Posted 叶祖辉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了复选框式查询 例题租房子相关的知识,希望对你有一定的参考价值。

技术分享
<!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>
<?php

$db = new mysqli("localhost","root","726","housedb");
//一共有四个条件
$tj1 = "1=1";
$tj2 = "1=1";
$tj3 = "1=1";
$tj4 = "1=1";
//区域的条件
if(!empty($_POST["qx"]) && count($_POST["qx"])>0)//判断区域有没有传入数据,qs是一个数组  并且它数量大于0
{
    
   $qx = $_POST["qx"];    
   $str = implode("‘,‘",$qx);      分隔符 返回一个字符串
       $tj1 = " area in(‘{$str}‘) ";     
}
//租赁类型的条件
if(!empty($_POST["zl"]) && count($_POST["zl"])>0)
{
    
    $zl = $_POST["zl"];
    //code in(‘类型‘,‘数量‘,‘都好久‘,‘队伍‘,‘额‘)
    $str = implode("‘,‘",$zl);
    
    $tj2 = " renttype in(‘{$str}‘) ";
}
//房屋类型的条件
if(!empty($_POST["fw"]) && count($_POST["fw"])>0)
{
    
    $fw = $_POST["fw"];
    //code in(‘类型‘,‘数量‘,‘都好久‘,‘队伍‘,‘额‘)
    $str = implode("‘,‘",$fw);
    
    $tj3 = " housetype in(‘{$str}‘) ";
}
//关键字的条件
if(!empty($_POST["key"]))    
{
    $key = $_POST["key"];
    $tj4 = " keyword like ‘%{$key}%‘ ";     
}

?>


<h1>租房子</h1>
<form action="zfchaxun.php" method="post">
<div>区域:<input type="checkbox" onclick="checkall(this)"  />全选</div>
<div>
<?php
$sqlq = "select distinct area from house";
$rq = $db->query($sqlq);
$aq  = $rq->fetch_all();
foreach($aq as $v)
{
    echo "<input type=‘checkbox‘ name=‘qx[]‘ value=‘{$v[0]}‘> {$v[0]}";
}
?>
</div>
<br />
<div>租赁类型:<input type="checkbox"  />全选</div>
<div>
<?php
$sqlz = "select distinct renttype from house";
$rz = $db->query($sqlz);
$az  = $rz->fetch_all();
foreach($az as $v)
{
    echo "<input type=‘checkbox‘ name=‘zl[]‘ value=‘{$v[0]}‘> {$v[0]}";  //设置name值
}
?>
</div>
<br />
<div>房屋类型:<input type="checkbox"  />全选</div>
<div>
<?php
$sqlf = "select distinct housetype from house";
$rf = $db->query($sqlf);
$af  = $rf->fetch_all();
foreach($af as $v)
{
    echo "<input type=‘checkbox‘ name=‘lx[]‘ value=‘{$v[0]}‘> {$v[0]}";
}
?>
</div>
<br />
<div>关键字:<input type="text" name="key" />
<input type="submit" value="查询" />
</div>
<br />
</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
$sqlall = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
$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");
    
    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>
技术分享

以上是关于复选框式查询 例题租房子的主要内容,如果未能解决你的问题,请参考以下文章

流程控制

错误 - EXC_BREAKPOINT(代码=1,子代码=0x100308448)

iContact卷曲子代码

unordered系列关联式容及应用例题

创建广告时出现代码 200 和子代码 1487194 的 Facebook 错误背后的原因是啥?

在 SpriteKit 中出现错误。 - 线程 1:EXC_BREAKPOINT(代码=1,子代码=0x1007351fc)