代码如下:

<!DOCTYPE html>

<html>

php查询并分页PHP衔接数据库实现多前提查询与分页功效 Bootstrap

<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='75544460b951f181 yangshi'><input type='checkbox' class='4460b951f181dcb4 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='b951f181dcb42404 ys'><input type='checkbox' class='f181dcb424047334 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='dcb4240473346dcf yangshi'><input type='checkbox' class='240473346dcf0dee 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>