租房子查询练习

<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;
    }
    }

}
时间: 2024-08-06 16:06:44

租房子查询练习的相关文章

租房子查询

1.发布房屋信息 发布页面: <!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

PHP-----练习-------租房子-----增删改查,多条件查询

练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php 1 <?php 2 class DBDA 3 { 4 public $fuwuqi="localhost"; //服务器地址 5 public $yonghuming="root";//用户名 6 public $mima="";//密码 7 8 public $dbconnect;

复选框式查询 例题租房子

<!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-

练习题投票和租房子

一:投票,连个页面都引用了DBDA封装类 <!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

增删改查租房子练习题

租房子练习题:重要颜色 1.模仿get传值到处理php页面:<a href='shanchu.php?c={$v[0]}' onclick=\"return confirm('确定删除吗?')\">删除</a> 2.删除页面显示确定删除提示框:<a href='shanchu.php?c={$v[0]}' onclick=\"return confirm('确定删除吗?')\">删除</a> 主页面: <body

php封装+租房子练习题

第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = "root"; public $pwd = "root"; public $dbname = "dbname"; public function Query($sql,$type=1)//两个参数,第二个参数代表默认值 { $db = new MySQLi($t

11月6日上午PHP练习《租房子》解析

一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming="root";//用户名 public $mima="";//密码 public $dbconnect;//连接对象 //操作数据库的方法 //$sql代表需要执行的SQL语句 //$type代表SQL语句的类型,1代表查询,2代表增删

php之租房子练习

一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming="root";//用户名 public $mima="";//密码 public $dbconnect;//连接对象 //操作数据库的方法 //$sql代表需要执行的SQL语句 //$type代表SQL语句的类型,1代表查询,2代表增删

php租房子批量搜索例题

租房子例题是用来练习多条件查询以及批量选择的典型例题,题面是这样的: 首先要分别建立区域.租赁类型.房屋类型的复选界面,遍历出所有数据,这里用无边框表格创建: <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td>区域:<input type="checkbox" name="qx" onclic