码迷,mamicode.com
首页 > 数据库 > 详细

多条件查询(php+mysql) 租房子例子

时间:2016-11-06 14:07:54      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:select   remove   lsp   pre   text   ble   eth   table   cli   

<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="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>

  

多条件查询(php+mysql) 租房子例子

标签:select   remove   lsp   pre   text   ble   eth   table   cli   

原文地址:http://www.cnblogs.com/gaojunshan/p/6034974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!