代码如下:

<!DOCTYPE html>

<html>

php判断链接正常PHP衔接数据库实现多前提查询与分页功效 GraphQL

<head>

<meta charset=\"大众UTF-8\"大众>

<title>租屋子</title>

<script src=\公众bootstrap/js/jquery-1.11.2.min.js\"大众></script>  //引入bootstrap前端框架的三个文件

<script src=\"大众bootstrap/js/bootstrap.min.js\"大众></script>

<link href=\公众bootstrap/css/bootstrap.min.css\公众 rel=\公众stylesheet\公众 type=\"大众text/css\"大众/>

</head>

<style>

.yangshi{

margin-left: 69px;

}

.ys{

margin-left: 69px;

}

.juli{

margin-left: 28px;

}

</style>

<body>

<form action=\公众rental.php\"大众 method=\"大众get\公众 style=\"大众margin-top: -145px;\"大众>  //form表单中利用get办法进行提交

<div style=\"大众width: 80%; height: 650px; background-image: url(./img/魅力罗兰Music炫图13.jpg); margin-left: 150px; margin-top: 150px;\公众>

<div style=\公众margin-left: 20px;\"大众>

<h1 style=\公众margin-left: 40%; pading-top: 20px;\公众>租屋子</h1>

<div class=\"大众juli\"大众>区域:<input type=\"大众checkbox\公众 class=\"大众ck1\"大众 onclick=\公众qx(this)\"大众> 全选</div>

<div>

 //连接数据库并利用去重查询取出列名为区域的这一组数据

<?php

require_once \"大众./DBDA.class.php\公众;

require_once \"大众./page.class.php\"大众;

$db = new DBDA();

$sqy = \公众select distinct area from housedb\"大众; //去重查询

$aqy =$db->query($sqy,0);

foreach($aqy as $v){

echo \"大众<span class='4fab49fb0fbb158a yangshi'><input type='checkbox' class='49fb0fbb158adfc1 ck1' name='qy[]' value='{$v[0]}'> {$v[0]}</span>\公众;

}

?>

</div>

</div>

效果如图:

<div style=\公众margin-left: 20px; margin-top: 20px;\"大众>

<div>租房类型:<input type=\"大众checkbox\"大众 class=\"大众ck2\"大众 onclick=\"大众zflx(this)\公众> 全选</div>

<div>

//连接数据库并利用去重查询取出列名为租房类型的这一组数据

<?php

$srt = \"大众select distinct renttype from housedb\公众;

$art = $db->query($srt,0);

foreach($art as $v){

echo \公众<span class='0fbb158adfc14a72 ys'><input type='checkbox' class='158adfc14a72ed17 ck2' name='zflx[]' value='{$v[0]}'> {$v[0]}</span>\"大众;

}

?>

</div>

效果如图:

<div style=\"大众margin-top: 20px;\"大众>

<div class=\公众juli\"大众>户型:<input type=\"大众checkbox\"大众 class=\公众ck3\"大众 onclick=\"大众hx(this)\"大众> 全选</div>

<div>

//连接数据库并利用去重查询取出列名为户型的这一组数据

<?php

$sht = \"大众select distinct housetype from housedb\公众;

$aht = $db->query($sht,0);

foreach($aht as $v){

echo \公众<span class='dfc14a72ed17e396 yangshi'><input type='checkbox' class='4a72ed17e3962c29 ck3' name='hx[]' value='{$v[0]}' > {$v[0]}</span>\"大众;

}

?>

</div>

</div>

效果如图:

</div>

<div style=\公众margin-top: 20px; margin-left: 20px;\"大众>

<span class=\"大众glyphicon glyphicon-search\"大众 style=\公众margin-top: 10px; float: left;\"大众></span>

 //关键字查询

<input type=\公众text\"大众 class=\"大众form-control\"大众 name=\公众keyword\"大众 placeholder=\"大众关键字搜索\"大众 style=\公众max-width: 120px;float: left;\"大众>

<button type=\"大众submit\公众 class=\"大众btn btn-danger\"大众style=\"大众float: left; margin-left: 20px;\"大众>搜索</button>

效果如图:

</div>

//利用表格在页面输出全部数据信息

<table class=\公众table table-bordered\"大众>

<thead>

<tr>

<th>关键字</th>

<th>区域</th>

<th>屋子面积</th>

<th>租价</th>

<th>租房类型</th>

<th>户型</th>

</tr>

</thead>

<tbody>

<?php

$tj1 = \公众 1=1 \"大众;  //分别对不同查询的条件做一个恒成立的条件

$tj2 = \公众 1=1 \"大众;

$tj3 = \"大众 1=1 \"大众;

$tj4 = \公众 1=1 \"大众;

if(!empty($_GET[\"大众qy\"大众])){  //区域的条件判断

$qy = $_GET[\"大众qy\"大众];

$str = implode(\"大众','\公众, $qy);

$tj1 = \公众area in ('{$str}')\"大众;

}

if(!empty($_GET[\"大众zflx\公众])){  //租房类型的条件判断

$zflx = $_GET[\"大众zflx\"大众];

$str = implode(\"大众','\"大众, $zflx);

$tj2 = \"大众renttype in ('{$str}')\"大众;

}

if(!empty($_GET[\"大众hx\"大众])){  //户型的条件判断

$hx = $_GET[\公众hx\公众];

$str = implode(\公众','\"大众, $hx);

$tj3 = \公众housetype in ('{$str}')\"大众;

}

if(!empty($_GET[\"大众keyword\"大众])){  //关键字查询的条件判断

$keyword = $_GET[\"大众keyword\"大众];

$tj4 = \"大众keyword like '%{$keyword}%'\公众;

}

$zts = \"大众select count() from housedb where {$tj1} and {$tj2} and {$tj3} and {$tj4}\"大众;  

$ats = $db->query($zts,0);

$page = new page($ats[0][0],3);  //分页查询取总数,设置每页显示的行数据

效果如图:

$sql = \公众select from housedb where {$tj1} and {$tj2} and {$tj3} and {$tj4}\公众.$page->limit;  //利用拼接字符串办法将调取分页方法与条件进行拼接

$arr = $db->query($sql,0);

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>\"大众;

}

?>

</tbody>

</table>

效果如图:

<div>

<?php

echo $page->fpage();

?>

</div>

</div>

</form>

</body>

<script>

 //利用JS实现全选功能

function qx(qx){

var ck1 = document.getElementsByClassName(\公众ck1\公众);

for(var i=0;i<ck1.length;i++){

ck1[i].checked=qx.checked;

}

}

function zflx(zflx){

var ck2 = document.getElementsByClassName(\公众ck2\"大众);

for(var i=0;i<ck2.length;i++){

ck2[i].checked=zflx.checked;

}

}

function hx(hx){

var ck3 = document.getElementsByClassName(\"大众ck3\"大众);

for(var i=0;i<ck3.length;i++){

ck3[i].checked=hx.checked;

}

}

</script>

</html>