租房子查询练习

Posted 随亦

tags:

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

<form action="chaxun.php" method="post">
<?php
include "zu.class.php";
$db = new zu();
echo "区域:&nbsp;<input type=‘checkbox‘ id=‘quq‘ onclick=‘qy()‘ />全选 <br><br> ";
$sql = "select distinct Area from zufangzi";
$r = $db->Query($sql);
foreach ($r as $v)
{
    echo "<input type=‘checkbox‘ class=‘qy‘ value=‘{$v[0]}‘ name=‘qy[]‘ /> {$v[0]}&nbsp;&nbsp;";
}
echo "<br><br><br>";
echo "租赁类型:&nbsp;<input type=‘checkbox‘ id=‘zlq‘ onclick=‘zl()‘ />全选 <br><br> ";
$sql1 = "select distinct RentType from zufangzi";
$r1 = $db->Query($sql1);
foreach ($r1 as $v1)
{
    echo "<input type=‘checkbox‘ class=‘zl‘ value=‘{$v1[0]}‘ name=‘zl[]‘ /> {$v1[0]}&nbsp;&nbsp;";
}
echo "<br><br><br>";
echo "房屋类型:&nbsp;<input type=‘checkbox‘ id=‘fwq‘ onclick=‘fw()‘ />全选 <br><br> ";
$sql2 = "select distinct HouseType from zufangzi";
$r2 = $db->Query($sql2);
foreach ($r2 as $v2)
{
    echo "<input type=‘checkbox‘ class=‘fw‘ value=‘{$v2[0]}‘ name=‘fw[]‘ /> {$v2[0]}&nbsp;&nbsp;";
}
echo "<br><br>关键字:<input type=‘text‘ name=‘gjz‘ value=‘‘ /><br><br>";
?>
<input type="submit" value="查询" />
</form>
<br />
<br />

<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr align="center">
<td>关键字</td>
<td>区域</td>
<td>建筑面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
</tr>

<?php
$zf1 = "1=1";
if(!empty($_POST["qy"]))
{
    $qy = $_POST["qy"];
    //var_dump ($qy);
    $qy1 = implode ("‘,‘",$qy);
    //var_dump($qy1);
    $zf1 = "Area in (‘{$qy1}‘)";
    //echo $zf1;
}
$zf2 = "1=1";
if(!empty($_POST["zl"]))
{
    $zl = $_POST["zl"]; 
    $zl1 = implode ("‘,‘",$zl);
    $zf2 = "RentType in (‘{$zl1}‘)";
}
$zf3 = "1=1";
if(!empty($_POST["fw"]))
{
    $fw = $_POST["fw"];
    $fw1 = implode ("‘,‘",$fw);
    $zf3 = "HouseType in (‘{$fw1}‘)";
}
$zf4 = "1=1";
if(!empty($_POST["gjz"]))
{
    $gjz = $_POST["gjz"];
    $zf4 = "KeyWord like ‘%{$gjz}%‘";
}

//echo $zf1.$zf2.$zf3;

$s = "select * from zufangzi where {$zf1} and {$zf2} and {$zf3} and {$zf4}";
//echo $s;
$cx = $db->Query($s);
//var_dump($cx);
foreach ($cx as $cx1)
{
    echo "<tr align=‘center‘>
    <td>{$cx1[1]}</td>
    <td>{$cx1[2]}</td>
    <td>{$cx1[3]}</td>
    <td>{$cx1[4]}</td>
    <td>{$cx1[5]}</td>
    <td>{$cx1[6]}</td>
 </tr>";
}

 


?>
</table>


<script>
function qy()
{
    var qy = document.getElementById("quq").checked;
    var dx = document.getElementsByClassName("qy");
    for(var i=0;i<dx.length;i++)
    {
    dx[i].checked = qy;
    }
}
function zl()
{
    var zl = document.getElementById("zlq").checked;
    var dx = document.getElementsByClassName("zl");
    for(var i=0;i<dx.length;i++)
    {
    dx[i].checked = zl;
    }
}
function fw()
{
    var fw = document.getElementById("fwq").checked;
    var dx = document.getElementsByClassName("fw");
    for(var i=0;i<dx.length;i++)
    {
    dx[i].checked = fw;
    }
}
</script>

<?php
class zu
{
    public $host = "localhost";
    public $uid = "root";
    public $pwd = "";

    public function Query($sql,$type = 0,$db = "news")
    {
    $d = new mysqli($this->host,$this->uid,$this->pwd,$db);
    !mysqli_connect_error() or die("连接失败");
    $result = $d->query($sql);
    if($type==0)
    {
    return $result->fetch_all();
    } 
    else
    {
    return $result;
    }
    }

}

 

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

php练习 租房子

PHP租房子练习

租房子练习

php租房子批量搜索例题

练习:租房子

增删改查租房子练习题