php 租房子练习

Posted 哔哩哔哩干杯

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于php 租房子练习的主要内容,如果未能解决你的问题,请参考以下文章

php 租房子练习

PHP租房子练习

PHP 练习3:租房子

php之租房子练习

php封装+租房子练习题

增删改查租房子练习题