Search. php)
1. Generate a query statement:
Copy codeThe Code is as follows:
<?
$ Conn = mysql_connect ("localhost", "root ","");
$ Db = mysql_select_db ("lingyun ");
$ Query = "select * from message where tradetype = '". $ tradetype. "'"; // transaction type, such as rent or sale
$ SQL = $ SQL. "wuye = '". $ wuye ."'";
If ($ housetype! = "Unlimited "){
$ Query. = "& housetype = '". $ housetype. "'"; // house type, such as Room 2, Room 1, Room 3, and room 2
}
If ($ degree! = "Unlimited "){
$ Query. = "& degree = '". $ degree. "'"; // new or old
}
If ($ wuye! = "Unlimited "){
$ Query. = "& wuye = '". $ wuye. "'"; // property types such as housing and shops
}
If ($ price2! = ""){
Switch ($ price1 ){
Case "greater ":
$ Query. = "& price> '". $ price2. "'"; // price
Break;
Case "equal ":
$ Query. = "& price = '". $ price2 ."'";
Break;
Case "less ":
$ Query. = "& price <'". $ price2 ."'";
Break;
}
}
If ($ area2! = ""){
Switch ($ area1 ){
Case "greater ":
$ Query. = "& area> '". $ area2. "'"; // area
Break;
Case "equal ":
$ Query. = "& area = '". $ area2 ."'";
Break;
Case "less ":
$ Query. = "& area <'". $ area2 ."'";
Break;
}
}
Switch ($ pubdate) {// release date
Case "within this week ":
$ Query. = "& TO_DAYS (NOW ()-TO_DAYS (date) <= 7 ";
Break;
Case "within one month ":
$ Query. = "& TO_DAYS (NOW ()-TO_DAYS (date) <= 30 ";
Break;
Case "within three months ":
$ Query. = "& TO_DAYS (NOW ()-TO_DAYS (date) <= 91 ";
Break;
Case "within six months ":
$ Query. = "& TO_DAYS (NOW ()-TO_DAYS (date) <= 183 ";
Break;
}
If ($ address! = ""){
$ Query. = "& address like '% $ address %'"; // address
}
If (! $ Page ){
$ Page = 1;
}
?>
Ii. Output query results:
Copy codeThe Code is as follows:
<? Php
If ($ page ){
$ Page_size = 20;
$ Result = mysql_query ($ query );
# $ Message_count = mysql_result ($ result, 0, "total ");
$ Message_count = 10;
$ Page_count = ceil ($ message_count/$ page_size );
$ Offset = ($ page-1) * $ page_size;
$ Query = $ query. "order by date desc limit $ offset, $ page_size ";
$ Result = mysql_query ($ query );
If ($ result ){
$ Rows = mysql_num_rows ($ result );
If ($ rows! = 0 ){
While ($ myrow = mysql_fetch_array ($ result )){
Echo "<tr> ";
Echo "<td width = '15' height = '12'> </td>";
Echo "<td width = '000000' height = '12'> $ myrow [id] $ myrow [tradetype] $ myrow [address] $ myrow [wuye] ($ myrow [housetype ]) <font style = 'font-size: 9pt '> [$ myrow [date] </font> ";
Echo "</td> ";
Echo "<td width = '75' height = '12'> <a href = 'view _ d. php? Code = $ myrow [code] 'target = '_ blank'> details </a> </td> ";
Echo "</tr> ";
}
}
Else echo "<tr> <td> <div align = 'center'> <br> no matching record found </div> & lt; /td> </tr> ";
}
$ Prev_page = $ page-1;
$ Next_page = $ page 1;
Echo "<div align = 'center'> ";
Echo "no.". $ page. "/". $ page_count. "page ";
If ($ page <= 1 ){
Echo "| page 1 | ";
}
Else {
Echo "<a href = '$ PATH_INFO? Page = 1'> | page 1 | </a> ";
}
Echo "";
If ($ prev_page <1 ){
Echo "| Previous Page | ";
}
Else {
Echo "<a href = '$ PATH_INFO? Page = $ prev_page '> | Previous page | </a> ";
}
Echo "";
If ($ next_page> $ page_count ){
Echo "| next page | ";
}
Else {
Echo "<a href = '$ PATH_INFO? Page = $ next_page '> | next page | </a> ";
}
Echo "";
If ($ page >=$ page_count ){
Echo "| last page | ";
}
Else {
Echo "<a href = '$ PATH_INFO? Page = $ page_count '> | last page | </a> ";
}
Echo "</div> ";
}
Else {
Echo "<p align = 'center'> no rental information is available now! </P> ";
}
Echo "?>
</Table>