zoukankan      html  css  js  c++  java
  • 多条件查询(php+mysql) 租房子例子

    <body>
    <?php
    
    //多条件
    $tiaojian2= " 2=2 ";
    $attr2 = "";
    //判断区域
    if(!empty($_POST["area"]))
    {
    	$attr2 = $_POST["area"];
    	$str2 = implode("','",$attr2);
    	$tiaojian2 = "area in('{$str2}')";
    }
    //多条件
    $tiaojian3= " 2=2 ";
    $attr3 = "";
    //判断房屋类型
    if(!empty($_POST["renttype"]))
    {
    	$attr3 = $_POST["renttype"];
    	$str3 = implode("','",$attr3);
    	$tiaojian3 = "renttype in('{$str3}')";
    }
    //多条件
    $tiaojian4= " 2=2 ";
    $attr4 = "";
    //判断租赁类型
    if(!empty($_POST["houesetype"]))
    {
    	$attr4 = $_POST["houesetype"];
    	$str4 = implode("','",$attr4);
    	$tiaojian4 = "houesetype in('{$str4}')";
    }
    
    ?>
    <form action="sousuoyemian.php" method="post">
    
        
        <div>区  域:<input type="checkbox" onclick="quanxuanqu(this)"/>全选
           <?php
    	          $tj=" and 1=1 ";
    	   if(!empty($_POST["gjz"]) && $_POST["gjz"]!== "" )
    	   {  $tj=" and kerword like '%{$_POST['gjz']}%' ";
    		} 
                  include("fengzhuang.php");
    			  
                   $db = new FENG();
                   $s="select * from house";
                   $a=$db->query($s);
                   echo"<div>";
                   foreach($a as $v)
                   {
                     echo"<input type='checkbox'  class='quyu' value='$v[2]' name='area[]'/>{$v[2]}";
                   }
                   echo"</div>";
        ?>
        </div><br />
        
        <div>房屋类型:<input type="checkbox" onclick="quanxuanfang(this)"/>全选
          <?php
        
                   echo"<div>";
                   foreach($a as $v)
                   {
                     echo"<input type='checkbox'  class='fangwu' value='$v[5]' name='renttype[]'/>{$v[5]}";
                   }
                   echo"</div>";
        ?>
        </div><br />
        
        <div>租赁类型:<input type="checkbox" onclick="quanxuanzu(this)"/>全选
          <?php
                   echo"<div>";
                   foreach($a as $v)
                   {
                     echo"<input type='checkbox' class='zulin' value='$v[6]' name='houesetype[]'/>{$v[6]}";
                   }
                   echo"</div>";
        ?>
        </div><br />
        
        <!-- 关键字查询 -->
        <div>关 键 字:<input type="text" name="gjz"/></div>
        <div><input type="submit" value="搜索" /></div>
    </form>
    
       <table style="100%" border="1" cellpadding="0" cellspacing="0">
             <tr>
                
                <td>关键字</td>
                <td>区域</td>
                <td>使用面积</td>
                <td>租金</td>
                <td>租赁类型</td>
                <td>房屋类型</td>
             </tr>
       
              <?php
    		  		 
    		   $sql="select * from house where  {$tiaojian2} and  {$tiaojian3} and {$tiaojian4} ".$tj;
    		   
    		   $ar=$db->query($sql);
    		  
    		   foreach($ar as $v)
    		   {
    			  echo"<tr>";
    			  echo"<td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td><td>{$v[5]}</td><td>{$v[6]}</td>";  
    			  echo"</tr>"; 
    			}
    		  
    		  ?>
       
       </table>
     
    
    <script type="text/javascript">
      
       function  quanxuanqu(qu)
       {
    	   //找到下面所有的复选框
    	   var  c=document.getElementsByClassName("quyu");
    	   //遍历所有复选框,设置选中状态
    	   for (var i=0; i<c.length; i++)
    	   {
    		   if(qu.checked)
    		   {
    			 c[i].setAttribute("checked","checked");
    		   }
    		   else
    		    {
    			 c[i].removeAttribute("checked");  
    		    }  
    			 
    	   }
    	   
    	   
    	} function  quanxuanfang(fang)
       {
    	   //找到下面所有的复选框
    	   var  c=document.getElementsByClassName("fangwu");
    	   //遍历所有复选框,设置选中状态
    	   for (var i=0; i<c.length; i++)
    	   {
    		   if(fang.checked)
    		   {
    			 c[i].setAttribute("checked","checked");
    		   }
    		   else
    		    {
    			 c[i].removeAttribute("checked");  
    		    }  
    			 
    	   }
    	   
    	   
    	}
    	
    	 function  quanxuanzu(zu)
       {
    	   //找到下面所有的复选框
    	   var  c=document.getElementsByClassName("zulin");
    	   //遍历所有复选框,设置选中状态
    	   for (var i=0; i<c.length; i++)
    	   {
    		   if(zu.checked)
    		   {
    			 c[i].setAttribute("checked","checked");
    		   }
    		   else
    		    {
    			 c[i].removeAttribute("checked");  
    		    }  
    			 
    	   }
    	   
    	   
    	}
      </script>
    
    </body>
    

      

  • 相关阅读:
    ubuntu12.04启动系统时报错
    TCP&HTTP协议详解
    nginx日志分析、切割与防盗链
    Nginx Rewrite规则详解
    nginx location深入剖析
    hadoop自动安装脚本
    极易中文分词
    朴素贝叶斯算法分析及java 实现
    随机森林(Random Forest)
    ubuntu 13.04 安装 JDK
  • 原文地址:https://www.cnblogs.com/gaojunshan/p/6034974.html
Copyright © 2011-2022 走看看