PHP租房子练习
2016-06-21 11:05
513 查看
租房查询
<!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> </head> <body> <h1>租房查询</h1> <form action="zufangchaxun.php" method="post"> <div>区域:<input type="checkbox" onclick="CheckAll(this,'qy')"/>全选</div> <div> <?php include("DBDA.class.php"); $db=new DBDA(); $sqlqy="select distinct Area from house";//distinct去重 $attrqy=$db->Query($sqlqy); foreach($attrqy as $v) { echo "<input class='qy' type='checkbox' value='{$v[0]}' name='qy[]'/>$v[0] "; } ?> </div><br /> <div>租赁类型:<input type="checkbox" onclick="CheckAll(this,'zllx')"/>全选</div> <div> <?php $sqlzllx="select distinct RentType from house"; $attrzllx=$db->Query($sqlzllx); foreach($attrzllx as $v) { echo "<input class='zllx' type='checkbox' value='{$v[0]}' name='zllx[]'/>$v[0] "; } ?> </div><br /> <div>房屋类型:<input type="checkbox" onclick="CheckAll(this,'fwlx')"/>全选</div> <div> <?php $sqlfwlx="select distinct HouseType from house"; $attrfwlx=$db->Query($sqlfwlx); foreach($attrfwlx as $v) { echo "<input class='fwlx' type='checkbox' value='{$v[0]}' name='fwlx[]'/>$v[0] "; } ?> </div><br /> <div>关键字:<input type="text" name="key"/></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["qy"])) { $str1=implode("','",$_POST["qy"]); $tj1="Area in ('{$str1}')"; } if(!empty($_POST["zllx"])) { $str2=implode("','",$_POST["zllx"]); $tj2="RentType in ('{$str2}')"; } if(!empty($_POST["fwlx"])) { $str3=implode("','",$_POST["fwlx"]); $tj3="HouseType in ('{$str3}')"; } if($_POST["key"]!="") { $tj4="KeyWord like '%{$_POST['key']}%'"; } } //总条件 $ztj=" where ($tj1) and ($tj2) and ($tj3) and ($tj4)"; $sql="select * from house".$ztj; echo $sql; $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> </body> <script type="text/javascript"> function CheckAll(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> </html>
相关文章推荐
- PHP投票练习
- php中命名空间的使用
- PHP面向对象总结
- 使用phpstom的点点滴滴记录,持续更新中...
- php中的学习笔记
- PHP加载类
- 单例模式
- php读取XML简单例子
- PHP输入流php://input介绍
- JHTP练习题及课题_第四章_控制语句Part 1-赋值、++、--运算符
- 亚马逊服务器搭建pptp方法
- 6月17日 TP表单验证
- TP学习笔记
- 用ChrootDirectory限制SFTP登录的用户只能访问指定目录且不能进行ssh登录
- 将vim打造成php的IDE开发环境
- yii\base\InvalidConfigException The directory is not writable by the Web process
- vsftp的默认目录那点事
- yii2 session处理
- SFTP上传文件详解
- laravel运行composer update时出现如下错误信息的解决方案