代码如下:

<!DOCTYPE html>

<html>

php多条件判断PHP衔接数据库实现多前提查询与分页功效 RESTful API

<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='5d8375696cdeece3 yangshi'><input type='checkbox' class='75696cdeece3d91a 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='6cdeece3d91a99ad ys'><input type='checkbox' class='ece3d91a99addfce 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='d91a99addfce56ab yangshi'><input type='checkbox' class='99addfce56aba72b 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>