php 租房子练习

本文介绍了一个基于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>
<?php
include("dbda.class.php");
$db=new dbda();

//查询区域
$sqy="select distinct area from house";
$aqy=$db->Query($sqy);
//查询租赁类型
$slx="select distinct renttype from house";
$alx=$db->Query($slx);
//查询房屋类型
$sfw="select distinct housetype from house";
$afw=$db->Query($sfw);

?>

<body>
<form action="zufang.php" method="post">
<h1>查询界面</h1>
<div>区域:<input type="checkbox" id="qyqx" 
onclick="quanxuan(this,'qy')" />全选</div>
<div>
<?php
foreach($aqy as $v)
{
    echo "<input class='qy' name='qy[]' type='checkbox' 
    value='{$v[0]}' />{$v[0]}&nbsp;";    
}
?>
</div><br />

<div>租赁类型:<input type="checkbox" id="lxqx" 
onclick="quanxuan(this,'lx')" />全选</div>
<div>
<?php
foreach($alx as $v)
{
    echo "<input class='lx' name='lx[]' type='checkbox' 
    value='{$v[0]}' />{$v[0]}&nbsp;";    
    }
?>
</div><br />

<div>房屋类型:<input type="checkbox" id="fwqx" 
onclick="quanxuan(this,'fw')" />全选</div>
<div>
<?php
foreach($afw as $v)
{
    echo "<input class='fw' name='fw[]' type='checkbox' 
    value='{$v[0]}' />{$v[0]}&nbsp;";    
    }
?>
</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))
    {
        if(!empty($_POST["qy"]))
        {
            //area in ('aa','bb','cc')
            $str1=implode("','",$_POST["qy"]);
            $tj1="area in ('{$str1}')";    
        }    
        if(!empty($_POST["lx"]))
        {
            $str2=implode("','",$_POST["lx"]);
            $tj2="renttype in ('{$str2}')";        
        }
        if(!empty($_POST["fw"]))
        {
            $str3=implode("','",$_POST["fw"]);
            $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 quanxuan(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>
View Code

 

转载于:https://www.cnblogs.com/bilibiliganbei/p/5597762.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值