Commercial Loans to Provident Fund loan conditions An example of a simple implementation of a multi-conditional query

Source: Internet
Author: User
In our site design process, often use multi-conditional query, the source of this article is a second-hand housing query example. In this case, we are going to be able to find the information that we need through a number of conditions, such as location, property type, house price, housing area and information release date. The following is the implementation process.
Query Condition Interface (abbreviated):
Query file (search.php)
First, generate the query statement:
$c
$db =mysql_select_db ("Lingyun");
$query = "SELECT * from message where tradetype= '". $tradetype. "'"; Types of transactions, such as rental, sale
$SQL = $SQL. "Wuye= '". $wuye. "'";
if ($housetype! = "Unlimited") {
$query. = "&& housetype=". $housetype. "'"; Housing type, such as two rooms, one hall, three rooms, two rooms
}
if ($degree! = "Unlimited") {
$query. = "&& degree=". $degree. "'"; New and Old degree
}
if ($wuye! = "Unlimited") {
$query. = "&& wuye=". $wuye. "'"; Property types such as housing, shops
}
if ($price 2!= "") {
Switch ($price 1) {
Case "Greater than":
$query. = "&& price>". $price 2. "'"; Price
Break
Case "equals":
$query. = "&& price=". $price 2. "'";
Break
Case "less than":
$query. = "&& price<". $price 2. "'";
Break
}
}
if ($area 2!= "") {
Switch ($area 1) {
Case "Greater than":
$query. = "&& area>". $area 2. "'"; Area
Break
Case "equals":
$query. = "&& area=". $area 2. "'";
Break
Case "less than":
$query. = "&& area<". $area 2. "'";
Break
}
}
Switch ($pubdate) {//release date
Case "within the Week":
$query. = "&& to_days (Now ())-to_days (date) <=7";
Break
Case "within one months":
$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;
}
?>
Second, output query results:
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 "";
echo "";
echo "$myrow [id] $myrow [tradetype] $myrow [address] $myrow [Wuye] ($myrow [Housetype]) [$myrow [Date]] ";
echo "";
echo "Detailed content";
echo "";
}
}
else echo "

No records were found to meet your criteria.";
}
$prev _page= $page-1;
$next _page= $page +1;
echo "";
echo "First". $page. " /". $page _count." Page ";
if ($page <=1) {
echo "| first page |";
}
else{
echo "| first page |";
}
echo "";
if ($prev _page<1) {
echo "| prev |";
}
else{
echo "| prev |";
}
echo "";
if ($next _page> $page _count) {
echo "| next page |";
}
else{
echo "| next page |";
}
echo "";
if ($page >= $page _count) {
echo "| last page |";
}
else{
echo "| last page |";
}
echo "";
}
else{
echo "

There are no housing rental information!

";
}
echo " ";
?>

If there is any problem in the use of the process, please contact me (yk_lingyun@21cn.com), welcome correction!
"The copyright of this article is owned by the author and house Orso near net, if need to reprint, please specify the author and source"

The above describes the commercial loan to the Provident Fund loan conditions A simple implementation of multi-conditional query, including the commercial loan to Provident Fund loan conditions of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.