题目:

示例图

本次只做图4这个表,因为之前的都已做过

自己在mydb数据库建了一个house表

如图:

自己做的代码:

<!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> <body>
<form  action="house_main.php" method="post">
<div>
区域:
    <input type="checkbox" name="qx1" onclick="checkall(this)" />全选
</div>
<div>    
         <?php
        $db = new MySQLi("localhost","root","root","mydb");
        $sqlqx = "select distinct area from house ";
        
        $resultqx = $db->query($sqlqx);
        while($arrqx = $resultqx->fetch_row())
        {
            
            echo"<input class='qx' type='checkbox' value='{$arrqx[0]}' name='qx[]' />{$arrqx[0]}";
        }
        
    ?>
</div>
<div>
租赁类型:
    <input type="checkbox" name="qx2" onclick="checkall2(this)"/>全选
</div>
<div>
    <?php
        
        $sqlqy = "select distinct renttype from house ";
        
        $resultqy = $db->query($sqlqy);
        while($arrqy = $resultqy->fetch_row())
        {
            
            echo"<input class='qy' type='checkbox' value='{$arrqy[0]}' name='qy[]'/>{$arrqy[0]}";
        }
    ?> </div> <div>
房屋类型:
    <input type="checkbox" name="qx3" onclick="checkall3(this)"/>全选
</div>
<div>
    <?php
        
        $sqlqz = "select distinct housetype from house";
        
        $resultqz = $db->query($sqlqz);
        while($arrqz = $resultqz->fetch_row())
        {
            
            echo"<input class='qz' type='checkbox' value='{$arrqz[0]}' name='qz[]' />{$arrqz[0]}";
        }
    ?>
</div> <div>
关键字:
<input  type="text" name="keyword"/>
</form>
<br /> <input type="submit" value="搜索" />
</div> </div>
<br />
<br />
<br /> </form>
<table width="50%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>关键字</td>
        <td>区域</td>
        <td>建筑面积</td>
        <td>租金</td>
        <td>租赁类型</td>
        <td>房屋类型</td>
    </tr>
    <?php
        $tj = "";
        $tj1 = "1=1";
        $tj2 = "2=2";
        $tj3 = "3=3";
        $tj4 = "4=4";
        if(!empty($_POST["qx"]) && count($_POST["qx"]>0))
        {
            $attr = $_POST["qx"];
            $str = implode("','",$attr);             $tj1 = "area in ('{$str}')";    
        }
        if(!empty($_POST["qy"]) && count($_POST["qy"]>0))
        {
            $attr = $_POST["qy"];
            $str = implode("','",$attr);
            
            $tj2 = "renttype in ('{$str}')";
        }
        if(!empty($_POST["qz"]) && count($_POST["qz"]>0))
        {
            $attr = $_POST["qz"];
            $str = implode("','",$attr);             $tj3 = "housetype in ('{$str}')";
        }
        if(!empty($_POST["keyword"]) && count($_POST["keyword"]>0))
        {
            $attr = $_POST["keyword"];
            $tj4 = "keyword like '%{$attr}%'";    
        }
        //$tj = " where {$tj1} and {$tj2} and {$tj3} and {$tj4} ";
        $sql = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4} ";
        $attry = $db->query($sql);
        while($arr = $attry->fetch_row())
        {
            echo"<tr>
            <td>{$arr[1]}</td>
            <td>{$arr[2]}</td>
            <td>{$arr[3]}</td>
            <td>{$arr[4]}</td>
            <td>{$arr[5]}</td>
            <td>{$arr[6]}</td>
            </tr>";
        }
    
    ?> </table>
</body>
</html>
<script type="text/javascript"> function checkall(qx)
{    //ck变量不能重复设置
    var ck = document.getElementsByClassName("qx");
    
    if(qx.checked)
    {
        for(var i=0;i<ck.length;i++)
        {
            ck[i].setAttribute("checked","checked");
        }
    }
    else
    {
        for(var i=0;i<ck.length;i++)
        {
            ck[i].removeAttribute("checked");
        }
    }
}
function checkall2(qy)
{
    var ck2 = document.getElementsByClassName("qy");
    
    if(qy.checked)
    {
        for(var i=0;i<ck2.length;i++)
        {
            ck2[i].setAttribute("checked","checked");
        }
    }
    else
    {
        for(var i=0;i<ck2.length;i++)
        {
            ck2[i].removeAttribute("checked");
        }
    }
}
function checkall3(qz)
{
    var ck3 = document.getElementsByClassName("qz");
    
    if(qz.checked)
    {
        for(var i=0;i<ck3.length;i++)
        {
            ck3[i].setAttribute("checked","checked");
        }
    }
    else
    {
        for(var i=0;i<ck3.length;i++)
        {
            ck3[i].removeAttribute("checked");
        }
    }
}
</script>

展示效果:

查询范例:

搜索结果如下:

php 数据库练习之租房子的更多相关文章

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

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

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

    练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...

  3. PHP实例练习--投票和租房子

    一,调查问卷 效果图:

  4. php 租房子(练习题)

    一.题目要求 1.功能描述   出租房屋数据管理及搜索页面 2.具体要求 (1) 创建数据库HouseDB,创建表House,要求如下: 二.题目做法 1.建立数据库 2.封装类文件 <?php ...

  5. php练习 租房子

    题目要求 1.封装类 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming=&q ...

  6. 最近要租房子,用Python看一下房源吧..

    前言:最近我的朋友想要租房子,为了装个b,决定运用技术去帮助他. 这个网站是什么我也不知道 反正是一个房子交易网站  http://www.ljia.net/ 设置请求头 headers = {'Ac ...

  7. PHP 练习(租房子)

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  8. PHP 练习3:租房子

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  9. php封装+租房子练习题

    第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = " ...

随机推荐

  1. 【WPF】弹窗定位、弹窗关闭后再打开的报错

    需求:点击按钮,打开一个弹窗. // 获得窗体实例 Window window = openDesignViewModel.View as Window; // 这是使用了WAF框架 //Window ...

  2. socket编程基础-字节序/IP/PORT转换/域名

    socket编程基础 网络IP操作函数 字符串的IP和32位的IP转换 #include <sys/socket.h> #inlcude <netinet/in.h> #inc ...

  3. uboot中变量env(收集)

    Env在u-boot中通常有两种存在方式,在永久性存储介质中(flash.NVRAM等),在SDRAM中.可配置不适用env的永久存储方式,但不常用.U-boot在启动时会将存储在永久性存储介质中的e ...

  4. Hadoop日志分析工具——White Elephant

    White Elephant 是一个Hadoop日志收集器和展示器,它提供了用户角度的Hadoop集群可视化.White Elephant 是全球最大的职业社交网站Linkedin开发的一套分析Had ...

  5. win10系统中UserManager 总是被禁用怎么解决?

    RT,也就是提示win10开始菜单和cortana无法工作.升级win10后一直被这个问题困扰,论坛也见有人发帖求助这类问题,百度了方法打开任务管理器进入服务更改User Manager启动类型为自动 ...

  6. 公司内网成功实现WSUS在不连外网的条件下更新补丁包!

    微软的WSUS的命令行很有帮助! 为了便于管理,WSUS服务器中提供了一个命令行工具WSUSUtil.exe,你可以使用它完成一些在WSUS管理控制台中不能进行的任务,例如导入导出数据等等.WSUSU ...

  7. MATLAB中常用的排列、组合、阶乘函数

    1.求n的阶乘,方法如下:a.factorial(n)b.gamma(n+1)c.v='n!'; vpa(v) 2.求组合(数),方法如下:a.combntns(x,m)    列举出从n个元素中取出 ...

  8. 结合使用 Oracle 和 Ruby on Rails 的补充

    本文是对此文的补充: 结合使用 Oracle 和 Ruby on Rails http://www.oracle.com/technetwork/cn/tutorials/rubyrails-0959 ...

  9. e667. 在给定图像中创建缓冲图像

    An Image object cannot be converted to a BufferedImage object. The closest equivalent is to create a ...

  10. Zookeeper 应用程序

    Zookeeper为分布式环境提供灵活的协调基础架构.ZooKeeper框架支持许多当今最好的工业应用程序.我们将在本章中讨论ZooKeeper的一些最显着的应用. 雅虎 ZooKeeper框架最初是 ...