第一个页面DBDA.class.php

<?php
class DBDA
{
public $host = "localhost";
public $uid = "root";
public $pwd = "root";
public $dbname = "dbname"; public function Query($sql,$type=1)//两个参数,第二个参数代表默认值
{
$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
$result = $db->query($sql); if($type=="1")//定义1类型的是查询,其它类型是增删改
{
return $result->fetch_all();
}else
{
return $result;
}
}
}

第二个页面main.php

<!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="main.php" method="post">
<div>
<div>区域:<input type="checkbox" onclick="xuan(this,'qx')" />全选</div>//传入两个参数
<div>
<?php
include("./DBDA.class.php");//引入类文件
$db = new DBDA();
$sqx = "select distinct area from housedb";
$aqx = $db->Query($sqx); foreach($aqx as $v)
{
echo "<input type='checkbox' name='qx[]' class='qx' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
</div>
<br />
<div>
<div>租赁类型:<input type="checkbox" onclick="xuan(this,'zl')" />全选</div>
<div>
<?php
$szl = "select distinct renttype from housedb";
$azl = $db->Query($szl); foreach($azl as $v)
{
echo "<input type='checkbox' name='zl[]' class='zl' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
</div>
<br />
<div>
<div>房屋类型:<input type="checkbox" onclick="xuan(this,'fw')" />全选</div>
<div>
<?php
$sfw = "select distinct housetype from housedb";
$afw = $db->Query($sfw); foreach($afw as $v)
{
echo "<input type='checkbox' name='fw[]' class='fw' value='{$v[0]}' />{$v[0]}";
}
?>
</div>
</div>
<br />
<div>关键字:<input type="text" name="keywords" />
<input type="submit" value="查询" />
</div>
<br />
</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["qx"]) && count($_POST["qx"])>0)
{
$str = implode("','",$_POST["qx"]);
$tj1 = " area in ('{$str}') ";
}
if(!empty($_POST["zl"]) && count($_POST["zl"])>0)
{
$str = implode("','",$_POST["zl"]);
$tj2 = " renttype in ('{$str}') ";
}
if(!empty($_POST["fw"]) && count($_POST["fw"])>0)
{
$str = implode("','",$_POST["fw"]);
$tj3 = " housetype in ('{$str}') ";
}
if(!empty($_POST["keywords"]))
{
$key = $_POST["keywords"];
$tj4 = " keyword like '%{$key}%' ";
} $sql = "select * from housedb where {$tj1} and {$tj2} and {$tj3} and {$tj4}"; echo $sql; $arr = $db->Query($sql); foreach($arr 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 xuan(qx,lei)//方法类似的尽量写一个,改变参数
{
var ck = document.getElementsByClassName(lei);
if(qx.checked)
{
for(var i=0;i<ck.length;i++)
{
ck[i].setAttribute("checked","checked");
}
}
else
{
for(var i=0;i<ck.length;i++)
{
ck[i].removeAttribute("checked");
}
}
}
</script>
</html>

最新文章

  1. 简单几何(线段相交)+模拟 POJ 3449 Geometric Shapes
  2. dedecms获取栏目下的频道列表
  3. CHAR数组转成STRING:C++
  4. some knowledge
  5. 经纬Zhang英拉垫背的企业家VC没有到这种地步这么卑鄙
  6. [转载]请教各位高手光盘版或者U盘版的BT保存配置的问题
  7. 20165220 学习基础和C语言基础调查
  8. Redis安装和基础介绍
  9. 初探VUX(基本官网上无特别无干货)
  10. java poi导入Excel(个人代码)
  11. Tomcat漏洞利用与安全加固实例分析
  12. FP-growth算法发现频繁项集(二)——发现频繁项集
  13. 整理iOS9适配中出现的坑
  14. 【转】Android SDK,ADT,API 版本的对应关系
  15. Docker存储方式选型建议
  16. iptables命令、规则、参数详解
  17. Java技术——Iterator和Enumeration的不同
  18. Spring事务管理Transaction
  19. Set(), Get() 真正的目的
  20. Xamarin XAML语言教程Xamarin.Forms中改变活动指示器颜色

热门文章

  1. 一句话绑定父函数的作用域this
  2. iOS 使用 github
  3. 360路由器+花生壳实现外网访问SVN服务器
  4. IOS 使用GCD改善性能
  5. css :active伪类的理解
  6. HTML 表单和输入
  7. &quot;类型初始值设定项引发异常&quot;
  8. SSM(Maven集成)
  9. CCNA网络工程师学习进程(9)GNS3的安装与配置
  10. tomact配置域名和端口直接访问网站