多条件查询(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" οnclick="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" οnclick="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" οnclick="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="width: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>

  

转载于:https://www.cnblogs.com/gaojunshan/p/6034974.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值