租房子

<!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>
<?php
include("DBDA.class.php");
$db= new DBDA();
?>

</head>
<body>


<form action="untitled-1.php" method="post">
<div>区域:<input  type="checkbox" onclick="quanxuan(this,'aa')"  />全选</div>
<?php
$sql="select distinct area from house";
$gjz=$db->query($sql);
foreach ($gjz as $g)
{
    echo " <input type='checkbox' class='aa' name='gjz[]' value='{$g[0]}' /> {$g[0]}";
    
    }
?>    

<div>租凭类型:<input  type="checkbox" onclick="quanxuan(this,'bb')" />全选</div>
<?php
$sql="select distinct renttype from house";
$fzlx=$db->query($sql);
foreach ($fzlx as $f)
{
    echo " <input type='checkbox'  class='bb' name='fzlx[]' value='{$f[0]}' /> {$f[0]}";
    
    }    
?>    

<div>房屋类型:<input  type="checkbox"  onclick="quanxuan(this,'cc')"/>全选</div>
<?php
$sql="select distinct housetype from house";
$fw=$db->query($sql);
foreach ($fw as $w)
{
    echo " <input type='checkbox' class='cc'name='fw[]' value='{$w[0]}' /> {$w[0]}";
    
    }    
?>    
    
    <?php
$ssname="";
if(!empty($_GET["gjzc"]))
{
    $ssname=$_GET["gjzc"];
    
}

?>
<div>关键字<input type="text" name="gjzc" value="<?php echo $ssname ?>" /></div>
<input type="submit"  value="查询" />
</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

$tj1=" 1=1 ";
$tj2=" 1=1 ";
$tj3=" 1=1 ";
$tj4=" 1=1 ";
    if(!empty($_POST))
    {    
        if(!empty($_POST["gjz"]))
        {
            $str=implode("','",$_POST["gjz"]);
            $tj1=" area in ('{$str}') ";
            
        }
        
        if(!empty($_POST["fzlx"]))
        {
            $str1=implode("','",$_POST["fzlx"]);
            $tj2=" renttype in('{$str1}') ";
            
            
        }
        
        if(!empty($_POST["fw"]))
        {
            
        $str2=implode("','",$_POST["fw"]);
        $tj3=" housetype in ('{$str2}') ";    
            
        }
         
          if( $_POST["gjzc"]!="")
          
          {
            $str4=$_POST["gjzc"];
            $tj4 = "  keyword like '%{$str4}%' ";  
              
          }
        
    }
        
        
        
        $sql="select * from house where {$tj1} and {$tj2}
        and {$tj3} and {$tj4} ";
        
        $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>
        
        <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>
</body>
</html>
原文地址:https://www.cnblogs.com/benpaodegegen/p/6038043.html