zoukankan      html  css  js  c++  java
  • PHP制作查询租房表

      1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      2 <html xmlns="http://www.w3.org/1999/xhtml">
      3 <head>
      4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      5 <title>无标题文档</title>
      6 </head>
      7 
      8 <body>
      9 
     10 <!--<textarea style=" overflow: scroll;"></textarea>文本域-->
     11 <!--当我点击查询的时候会把数据传到当前页面,提交到当前页面-->
     12 <?php
     13 $db = new MySQLi("localhost","root","511108","text");
     14 //在这个页面就能把提交的数据放到这是用了
     15 //做查询的时候传递过来几条数据就就做几个条件
     16 $tj1 = " 1=1 ";
     17 $tj2 = " 1=1 ";
     18 $tj3 = " 1=1 ";
     19 $tj4 = " 1=1 ";
     20 
     21 //区域的条件 
     22 //var_dump($_POST["qx"]);//测试输出用
     23 if(!empty($_POST["qx"]) && count($_POST["qx"])>0)//判断countyaodayu零如果等于零还是查所有
     24 {
     25     //$tj1 = "";
     26     $qx = $_POST["qx"];//这是一个数组把数组要转化字符串
     27     //select * from info where code in('类型','数量','','','')//数组里面每个元素就是一个值。如何拼成字符串:用拆分字符串implode方法(','拼接)
     28     $str = implode("','",$qx);
     29     //echo $str;//输出
     30     $tj1 = " area in('{$str}') ";//完整的条件
     31     //echo $tj1;//输出看看tj1 是不是完整条件
     32 }
     33 //租赁类型的条件
     34 if(!empty($_POST["zl"]) && count($_POST["zl"])>0)
     35 {
     36     $zl = $_POST["zl"];
     37     $str = implode("','",$zl);
     38     $tj2 = " renttype in('{$str}') ";    
     39 }
     40 //房屋类型的条件
     41 if(!empty($_POST["fw"]) && count($_POST["fw"])>0)
     42 {
     43     $fw = $_POST["fw"];
     44     $str = implode("','",$fw);
     45     $tj3 = " housetype in('{$str}') ";
     46     //echo $tj3;    //测试输出
     47 }
     48 //关键字的条件
     49 if(!empty($_POST["key"]))
     50 {
     51     $key = $_POST["key"];//把$_POST["key"]交给$key变量
     52     $tj4 = " keyword like '%{$key}%' ";//不为空就变成关键字模糊查询,把$key变量拿过来    
     53 }
     54 
     55 
     56 ?>
     57 
     58 
     59 <h1>租房</h1>
     60 <form action="fangwu12.php" method="post">
     61 <div>
     62     区域:
     63         <input type="checkbox" name="qx" />全选
     64 </div>
     65 <div>
     66     <?php
     67     $sqlq = "select distinct area from house";//去重distinct
     68     $rq = $db->query($sqlq);
     69     $aq = $rq->fetch_all();
     70     foreach($aq as $v)//循环输出
     71     {
     72         echo "<input type='checkbox' name='qx[]' value='{$v[0]}' />{$v[0]}";//    name='qx[]'以数组形式提交
     73     }
     74     ?>
     75 </div>
     76 <br/>
     77 
     78 <div>
     79     租赁类型:
     80         <input type="checkbox" name="qx" />全选</div>
     81 <div>
     82     <?php
     83     $sqlz = "select distinct renttype from house";//去重distinct
     84     $rz = $db->query($sqlz);
     85     $az = $rz->fetch_all();
     86     foreach($az as $v)//循环输出
     87     {
     88         echo "<input type='checkbox' name='zl[]' value='{$v[0]}' />{$v[0]}";    
     89     }
     90     ?>
     91 </div>
     92 <br/>
     93 
     94 <div>
     95     房屋类型:
     96         <input type="checkbox" name="qx" />全选</div>
     97 <div>
     98     <?php
     99     $sqlf = "select distinct housetype from house";//去重distinct
    100     $rf = $db->query($sqlf);
    101     $af = $rf->fetch_all();
    102     foreach($af as $v)//循环输出
    103     {
    104         echo "<input type='checkbox' name='fw[]' value='{$v[0]}' />{$v[0]} ";    
    105     }
    106     ?>
    107 </div>
    108 <br/>
    109 <div>
    110     关键字:
    111     <input type="text" name="key" />
    112     <input type="submit" value="查询" />
    113 </div>
    114 <table width="100%" border="1" cellpadding="0" cellspacing="0">
    115     <tr>
    116         <td>关键字</td>
    117         <td>区域</td>
    118         <td>建筑面积</td>
    119         <td>租金</td>
    120         <td>租赁类型</td>
    121         <td>房屋类型</td>
    122     </tr>
    123     <?php
    124     $sqlall = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
    125     //echo $sqlall;//什么也不选就是默认所有
         $rall = $db->query($sqlall); 126 $aall = $rall->fetch_all(); 127 foreach($aall as $v) 128 { 129 echo "<tr> 130 <td>{$v[1]}</td> 131 <td>{$v[2]}</td> 132 <td>{$v[3]}</td> 133 <td>{$v[4]}</td> 134 <td>{$v[5]}</td> 135 <td>{$v[6]}</td> 136 </tr>"; 137 } 138 139 ?> 140 141 142 </table> 143 144 </body> 145 </html>

      1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      2 <html xmlns="http://www.w3.org/1999/xhtml">
      3 <head>
      4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      5 <title>无标题文档</title>
      6 </head>
      7 
      8 <body>
      9 
     10 <!--<textarea style=" overflow: scroll;"></textarea>文本域-->
     11 <!--当我点击查询的时候会把数据传到当前页面,提交到当前页面-->
     12 <?php
     13 $db = new MySQLi("localhost","root","511108","text");
     14 //在这个页面就能把提交的数据放到这是用了
     15 //做查询的时候传递过来几条数据就就做几个条件
     16 $tj1 = " 1=1 ";
     17 $tj2 = " 1=1 ";
     18 $tj3 = " 1=1 ";
     19 $tj4 = " 1=1 ";
     20 
     21 //区域的条件 
     22 //var_dump($_POST["qx"]);//测试输出用
     23 if(!empty($_POST["qx"]) && count($_POST["qx"])>0)//判断countyaodayu零如果等于零还是查所有
     24 {
     25     //$tj1 = "";
     26     $qx = $_POST["qx"];//这是一个数组把数组要转化字符串
     27     //select * from info where code in('类型','数量','','','')//数组里面每个元素就是一个值。如何拼成字符串:用拆分字符串implode方法(','拼接)
     28     $str = implode("','",$qx);
     29     //echo $str;//输出
     30     $tj1 = " area in('{$str}') ";//完整的条件
     31     //echo $tj1;//输出看看tj1 是不是完整条件
     32 }
     33 //租赁类型的条件
     34 if(!empty($_POST["zl"]) && count($_POST["zl"])>0)
     35 {
     36     $zl = $_POST["zl"];
     37     $str = implode("','",$zl);
     38     $tj2 = " renttype in('{$str}') ";    
     39 }
     40 //房屋类型的条件
     41 if(!empty($_POST["fw"]) && count($_POST["fw"])>0)
     42 {
     43     $fw = $_POST["fw"];
     44     $str = implode("','",$fw);
     45     $tj3 = " housetype in('{$str}') ";
     46     //echo $tj3;    //测试输出
     47 }
     48 //关键字的条件
     49 if(!empty($_POST["key"]))
     50 {
     51     $key = $_POST["key"];//把$_POST["key"]交给$key变量
     52     $tj4 = " keyword like '%{$key}%' ";//不为空就变成关键字模糊查询,把$key变量拿过来    
     53 }
     54 
     55 
     56 ?>
     57 
     58 
     59 <h1>租房</h1>
     60 <form action="fangwu12.php" method="post">
     61 <div>
     62     区域:
     63         <input type="checkbox" onclick="checkall(this)" />全选
     64 </div>
     65 <div>
     66     <?php
     67     $sqlq = "select distinct area from house";//去重distinct
     68     $rq = $db->query($sqlq);
     69     $aq = $rq->fetch_all();
     70     foreach($aq as $v)//循环输出
     71     {
     72         echo "<input type='checkbox' name='qx[]' value='{$v[0]}' class='qxlist' />{$v[0]}";//    name='qx[]'以数组形式提交
     73     }
     74     ?>
     75 </div>
     76 <br/>
     77 
     78 <div>
     79     租赁类型:
     80         <input type="checkbox" name="qx" />全选</div>
     81 <div>
     82     <?php
     83     $sqlz = "select distinct renttype from house";//去重distinct
     84     $rz = $db->query($sqlz);
     85     $az = $rz->fetch_all();
     86     foreach($az as $v)//循环输出
     87     {
     88         echo "<input type='checkbox' name='zl[]' value='{$v[0]}' />{$v[0]}";    
     89     }
     90     ?>
     91 </div>
     92 <br/>
     93 
     94 <div>
     95     房屋类型:
     96         <input type="checkbox" name="qx" />全选</div>
     97 <div>
     98     <?php
     99     $sqlf = "select distinct housetype from house";//去重distinct
    100     $rf = $db->query($sqlf);
    101     $af = $rf->fetch_all();
    102     foreach($af as $v)//循环输出
    103     {
    104         echo "<input type='checkbox' name='fw[]' value='{$v[0]}' />{$v[0]} ";    
    105     }
    106     ?>
    107 </div>
    108 <br/>
    109 <div>
    110     关键字:
    111     <input type="text" name="key" />
    112     <input type="submit" value="查询" />
    113 </div>
    114 <table width="100%" border="1" cellpadding="0" cellspacing="0">
    115     <tr>
    116         <td>关键字</td>
    117         <td>区域</td>
    118         <td>建筑面积</td>
    119         <td>租金</td>
    120         <td>租赁类型</td>
    121         <td>房屋类型</td>
    122     </tr>
    123     <?php
    124     $sqlall = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
    125     //echo $sqlall;//什么也不选就是默认所有
    126     $rall = $db->query($sqlall);
    127     $aall = $rall->fetch_all();
    128     foreach($aall as $v)
    129     {
    130         echo "<tr>
    131         <td>{$v[1]}</td>
    132         <td>{$v[2]}</td>
    133         <td>{$v[3]}</td>
    134         <td>{$v[4]}</td>
    135         <td>{$v[5]}</td>
    136         <td>{$v[6]}</td>
    137     </tr>";    
    138     }
    139     
    140     ?>
    141 
    142 
    143 </table>
    144 <!--下是控制区域全选,上面有个区域-->
    145 <script type="text/javascript">
    146 
    147 function checkall(a)
    148 {
    149     var ck = document.getElementsByClassName("qxlist");
    150     <!--document.getElementById().setAttribute()用来设置属性的-->
    151     if(a.checked)
    152     {
    153         for(var i=0;i<ck.length;i++)<!--通过这个循环-->
    154         {
    155             ck[i].setAttribute("checked","checked");<!--由他控制全选-->    
    156         }
    157     }
    158     else
    159     {
    160         for(var i=0;i<ck.length;i++)
    161         {
    162             ck[i].removeAttribute("checked");    
    163         }
    164     }
    165 }
    166 
    167 </script>
    168 
    169 
    170 
    171 </body>
    172 </html>
    图一,图二是运行区域全选的功能

    图一图2

  • 相关阅读:
    品优购项目(web)
    Linux
    web前端面试题
    三级网络
    Vue报错:TypeError: Cannot create property ‘xxx‘ on string ‘xxxx
    vue 动态添加页面背景色
    vue 打开新页面 页面滚动到顶部
    ios 系统 h5 页面不发送请求
    小程序返回上一页
    小程序动态设置页面背景色、
  • 原文地址:https://www.cnblogs.com/aqxss/p/6219239.html
Copyright © 2011-2022 走看看