PHP Connection database for multi-conditional query and paging function--on the full instance operation of renting page

Source: Internet
Author: User
Tags button type zts

Rental page

The code is as follows:

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Rent a house </title>
<script src= "Bootstrap/js/jquery-1.11.2.min.js" ></script>//Introduction of three files in the bootstrap front-end framework
<script src= "Bootstrap/js/bootstrap.min.js" ></script>
<link href= "Bootstrap/css/bootstrap.min.css" rel= "stylesheet" type= "Text/css"/>
<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;" >submit in//form form using get method
<div style= "width:80%; height:650px; Background-image:url (./img/charm Roland Music 13.jpg); margin-left:150px; margin-top:150px; " >
<div style= "margin-left:20px;" >

<div class= "Juli" > Area: <input type= "checkbox" class= "Ck1" onclick= "QX (This)" > select all </div>
<div>

    //Connect to the database and use the deduplication query to remove this set of data with the column name as a region
<?php
Require_once "./dbda.class.php";
Require_once "./page.class.php";
$db = new Dbda ();
$sqy = "SELECT distinct area from Housedb"; Go to re-query
$aqy = $db->query ($sqy, 0);
foreach ($aqy as $v) {
echo "<span class= ' Yangshi ' ><input type= ' checkbox ' class= ' ck1 ' name= ' qy[] ' value= ' {$v [0]} ' > {$v [0]}</ Span> ";
}
?>
</div>
</div>

  Effect


<div style= "margin-left:20px; margin-top:20px; " >
<div> Rental Type: <input type= "checkbox" class= "Ck2" onclick= "ZFLX (This)" > select all </div>
<div>

     //Connect the database and use the deduplication query to remove this set of data that is listed as a rental type
<?php
$SRT = "SELECT distinct renttype from Housedb";
$art = $db->query ($srt, 0);
foreach ($art as $v) {
echo "<span class= ' ys ' ><input type= ' checkbox ' class= ' ck2 ' name= ' zflx[] ' value= ' {$v [0]} ' > {$v [0]}</span > ";
}
?>
</div>

  Effect

<div style= "margin-top:20px;" >
<div class= "Juli" > Type: <input type= "checkbox" class= "CK3" onclick= "HX (This)" > select all </div>
<div>

     //Connect the database and use the deduplication query to remove this set of data that is named Apartment
<?php
$sht = "SELECT distinct housetype from Housedb";
$aht = $db->query ($sht, 0);
foreach ($aht as $v) {
echo "<span class= ' Yangshi ' ><input type= ' checkbox ' class= ' ck3 ' name= ' hx[] ' value= ' {$v [0]} ' > {$v [0]}</ Span> ";
}
?>
</div>
</div>

  Effect
</div>

<div style= "margin-top:20px; margin-left:20px; " >
<span class= "Glyphicon glyphicon-search" style= "margin-top:10px"; Float:left; " ></span>

   Keyword Query
<input type= "text" class= "Form-control" name= "keyword" placeholder= "keyword search" style= "max-width:120px;float:left;" >
<button type= "Submit" class= "btn Btn-danger" style= "float:left; margin-left:20px; " > Search </button>

   effect
</div>
//Use the form to output all data information on the page
<table class= "Table table-bordered" >
<thead>
<tr>
<th> keywords </th>
<th> Area </th>
<th> House Area </th>
<th> Rental </th>
<th> Rental Type </th>
<th> type </th>
</tr>
</thead>
<tbody>
<?php
$TJ 1 = "1=1";//To make a constant setting condition for the conditions of different queries
$TJ 2 = "1=1";
$TJ 3 = "1=1";
$TJ 4 = "1=1";
if (!empty ($_get["qy")) {//area of the condition judgment
$qy = $_get["qy"];
$str = Implode ("', '", $qy);
$TJ 1 = "area in (' {$str} ')";
}
if (!empty ($_get["ZFLX")) {//rental type of condition judgment
$ZFLX = $_get["ZFLX"];
$str = Implode ("', '", $ZFLX);
$TJ 2 = "Renttype in (' {$str} ')";
}
if (!empty ($_get["HX"])) {//type of condition judgment
$HX = $_get["HX"];
$str = Implode ("', '", $HX);
$TJ 3 = "Housetype in (' {$str} ')";
}
if (!empty ($_get["keyword")) {//keyword query for conditional judgment
$keyword = $_get["keyword"];
$TJ 4 = "keyword like '%{$keyword}% '";
}

$zts = "SELECT count (*) from Housedb where {$TJ 1} and {$TJ 2} and {$TJ 3} and {$TJ 4}";
$ats = $db->query ($zts, 0);
$page = new Page ($ats [0][0],3);//Paging query Fetch total, set the row data displayed per page

  Effect



$sql = "SELECT * from Housedb where {$TJ 1} and {$TJ 2} and {$TJ 3} and {$TJ 4}". $page->limit;//Splicing The paging method with the condition by splicing string
$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>

  Effect
<div>
<?php
echo $page->fpage ();
?>
</div>
</div>
</form>
</body>
<script>

  //Use JS to achieve the full selection function
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>

PHP Connection database for multi-conditional query and paging function--on the full instance operation of renting page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.