租房子练习

<!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>
<style type="text/css">
.qylist
{
    float:left;
}
.zllist
{
    float:left;
}
.fwlist
{
    float:left;
}
</style>
</head>

<body>
<?php
    include("DBDA.php");
    $db = new DBDA();

    @$qytj = $_POST["qy"];
    @$zltj = $_POST["zl"];
    @$fwtj = $_POST["fw"];
    @$key = $_POST["key"];

    //造查询字符串
    $str1 = " 1=1";
    $str2 = " 1=1";
    $str3 = " 1=1";
    $str4 = " 1=1";

    //判断第一个条件是否有值
    if(count($qytj)>0)
    {
        $ss = implode("‘,‘",$qytj);
        $str1 = " Area in (‘{$ss}‘)";
    }
    //判断租赁类型
    if(count($zltj)>0)
    {
        $ss = implode("‘,‘",$zltj);
        $str2 = " RentType in (‘{$ss}‘)";
    }
    //判断房屋类型
    if(count($fwtj)>0)
    {
        $ss = implode("‘,‘",$fwtj);
        $str3 = " HouseType in (‘{$ss}‘)";
    }
    //判断关键字
    if($key!="")
    {
        $str4 = " KeyWord like ‘%{$key}%‘";
    }

    $sqltj = " where".$str1." and".$str2." and".$str3." and".$str4;

?>

<form action="0329House.php" method="post">
<div>
    <div style="margin-top:10px">区域:<input type="checkbox" id="qyall" name="qyall" onclick="CheckAll(this,‘qy‘)" />全选</div>
    <div>
        <?php
        $sqlqy = "select distinct(Area) from HouseDB";
        $attrqy = $db->Query($sqlqy);
        for($i=0;$i<count($attrqy);$i++)
        {
            echo "<div class=‘qylist‘>
            <input type=‘checkbox‘ name=‘qy[]‘ class=‘qy‘ value=‘{$attrqy[$i][0]}‘ />
            {$attrqy[$i][0]}
            </div>";
        }
        ?>
    </div>
    <div style="clear:both"></div>  <!--截断流  用来清除float-->
    <div style="margin-top:20px;">租赁类型:<input type="checkbox" id="zlall" name="zlall" onclick="CheckAll(this,‘zl‘)" />全选</div>

    <div>
        <?php
        $sqlzl = "select distinct(RentType) from HouseDB";
        $attrzl = $db->Query($sqlzl);
        for($i=0;$i<count($attrzl);$i++)
        {
            echo "<div class=‘zllist‘>
            <input type=‘checkbox‘ name=‘zl[]‘ class=‘zl‘ value=‘{$attrzl[$i][0]}‘ />
            {$attrzl[$i][0]}
            </div>";
        }
        ?>
    </div>
    <div style="clear:both"></div>
    <div style="margin-top:20px">房屋类型:<input type="checkbox" id="fwall" name="fwall" onclick="CheckAll(this,‘fw‘)" />全选</div>

       <div>
        <?php
        $sqlfw = "select distinct(HouseType) from HouseDB";
        $attrfw = $db->Query($sqlfw);
        for($i=0;$i<count($attrfw);$i++)
        {
            echo "<div class=‘fwlist‘>
            <input type=‘checkbox‘ name=‘fw[]‘ class=‘fw‘ value=‘{$attrfw[$i][0]}‘ />
            {$attrfw[$i][0]}
            </div>";
        }
        ?>
    </div>
    <div style="clear:both"></div>

    <div style="margin:20px 0px 20px 0px">关键字:<input type="text" name="key" /> &nbsp;<input type="submit" value="搜索" /></div>

</div>
</form>

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

    <?php

        $sqlall = "select * from HouseDB".$sqltj;
        $rall = $db->Query($sqlall);

        for($i=0;$i<count($rall);$i++)
        {
            echo "<tr>
            <td>{$rall[$i][1]}</td>
            <td>{$rall[$i][2]}</td>
            <td>{$rall[$i][3]}</td>
            <td>{$rall[$i][4]}</td>
            <td>{$rall[$i][5]}</td>
            <td>{$rall[$i][6]}</td>
            </tr>";

        }

    ?>

</table>

</body>
<script type="text/javascript">
function CheckAll(ck,cname)
{
    var all = document.getElementsByClassName(cname);
    for(var i=0;i<all.length;i++)
    {
        all[i].checked = ck.checked;
    }

}
</script>
</html>
时间: 2024-07-30 10:18:55

租房子练习的相关文章

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-