PHP connects to the database to implement multi-condition query and paging functions-for the complete instance operations on the rental page, php Paging

Source: Internet
Author: User

PHP connects to the database to implement multi-condition query and paging functions-for the complete instance operations on the rental page, php Paging

Rental page

The Code is as follows:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> house rental </title>
<Script src = "bootstrap/js/jquery-1.11.2.min.js"> </script> // three files that introduce 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"/>
</Head>
<Style>
. Yangshi {
Margin-left: 69px;
}
. Ys {
Margin-left: 69px;
}
. Juli {
Margin-left: 28px;
}
</Style>
<Body>
<Form action = "Marshal. php" method = "get"> // use the get method to submit a form.
<Div> // connect to the database and retrieve the group of data with the column name as the region using deduplicated queries.
<? Php
Require_once "./DBDA. class. php ";
Require_once "./page. class. php ";
$ Db = new DBDA ();
$ Sqy = "select distinct area from housedb"; // deduplication
$ 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> // connect to the database and use deduplicated queries to retrieve the group of data whose column is the rental type.
<? Php
$ Srt = "select distinct partition type 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> // connect to the database and retrieve the group of data with the column name of the house type by deduplication.
<? 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> // keyword Query
<Input type = "text" class = "form-control" name = "keyword" placeholder = "keyword search"> Effect
</Div>
// Use a table to output all data information on the page
<Table class = "table-bordered">
<Thead>
<Tr>
<Th> keyword </th>
<Th> region </th>
<Th> house area </th>
<Th> rental price </th>
<Th> rental type </th>
<Th> house type </th>
</Tr>
</Thead>
<Tbody>
<? Php
$ Tj1 = "1 = 1"; // create a uniform condition for different query conditions.
$ Tj2 = "1 = 1 ";
$ Tj3 = "1 = 1 ";
$ Tj4 = "1 = 1 ";
If (! Empty ($ _ GET ["qy"]) {// condition judgment of the Region
$ Qy = $ _ GET ["qy"];
$ Str = implode ("','", $ qy );
$ Tj1 = "area in ('{$ str }')";
}
If (! Empty ($ _ GET ["zflx"]) {// condition Determination of rental type
$ Zflx = $ _ GET ["zflx"];
$ Str = implode ("','", $ zflx );
$ Tj2 = "struct type in ('{$ str }')";
}
If (! Empty ($ _ GET ["hx"]) {// condition Determination of apartment type
$ Hx = $ _ GET ["hx"];
$ Str = implode ("','", $ hx );
$ Tj3 = "housetype in ('{$ str }')";
}
If (! Empty ($ _ GET ["keyword"]) {// condition judgment for keyword Query
$ 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); // retrieve the total number of page queries and set the row data displayed on each page

  Effect

 



$ SQL = "select * from housedb where {$ tj1} and {$ tj2} and {$ tj3} and {$ tj4 }". $ page-> limit; // Concatenates the paging method and condition using the concatenation 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 full selection
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>

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.