题目:

示例图

本次只做图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>

展示效果:

查询范例:

搜索结果如下:

最新文章

  1. 使用RestTemplate发送post请求
  2. Tplink客户端设置
  3. FreeRadius服务器安装以及error while loading shared libraries问题
  4. Django学习笔记之一
  5. file的这几个取得path的方法各有不同,下边说说详细的区别
  6. h5-3
  7. (八)Android广播接收器BroadcastReceiver
  8. linux下安装PHP的redis扩展
  9. TOGAF架构开发方法(ADM)之架构变更管理阶段
  10. highcharts的多级下钻以及图形形态转换
  11. C语言实现的排序
  12. Vue之生命周期函数和钩子函数详解
  13. 第30月第18天 autolayout代码
  14. Java设计模式之《模板模式》及使用场景
  15. Confluence 6 在你用户宏中使用参数
  16. ThinkCMF项目部署出现无法加载数据库驱动解决方案
  17. python 随机模块常用命令
  18. npm 代理的设置和取消
  19. lombok插件:Data自动get/set方法, Slf4j实现Logger的调用
  20. redis 的 docker 镜像使用

热门文章

  1. Android——适配器其他组件(AutoCompleteTextView:自动完成文本编辑框;Spinner:下拉列表)
  2. HDFS入门
  3. ansible result.stdout.find(&#39;running&#39;) != -1 判断状态
  4. easyui datagrid列拖拽
  5. socket和http
  6. CString常用函数
  7. Java集合类相关面试题
  8. Mac OS Yosemite 文件批量重命名
  9. 刚刚完成了在vs2013中通过 ef连接mysql数据库的工作。感觉没有想象中的简单。试了n次终于成功。故记录成功的方法,希望可以帮到大家
  10. Linux shell 学习