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>

时间: 2024-08-05 10:16:48

php 租房子练习的相关文章

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;

练习题投票和租房子

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

php练习 租房子

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

PHP 练习3:租房子

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

复选框式查询 例题租房子

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