如何在循环和内部循环值的同时获取两个值

时间:2016-12-01 15:14:11

标签: php

我有两张表add_projectsfloor_plan。在第二个表project_id很常见。在成功选择add_projects表格(此处我将获得project_id)的结果后,我想查看floor_table WHERE project_id='$project_id'的最低价格。我正在尝试如下,但我没有得到最小值。我该怎么做?

add_projects db structure floor_plan db structure

<?php
    include("admin/dbconfig.php");
    include("admin/functions.php");
    $property = $_POST['property']; // official shadow - 3
    $min_price = $_POST['min_price']; // 5-10
    $min_explode = explode("-",$min_price);
    $min1 = $min_explode[0]; // 5
    $min2 = $min_explode[1]; // 10
    /* $min1 = 5;
    $min2 = 10 */;
    $max_price = $_POST['max_price'];// 35-40
    $max_explode = explode("-",$max_price); 
    $max1 = $max_explode[0] ; // 35
    $max2 = $max_explode[1] ; // 40
    /*$max1 = 20;
    $max2 = 40; */
    $location = $_POST['location'];

    $query = "SELECT * FROM add_projects WHERE property='$property' AND property_type='3'";

    if ($min_price!='') {
        $query.=" AND total_price BETWEEN $min1 AND $min2";
        //SELECT * FROM add_projects1 WHERE property='3' AND total_price BETWEEN 5 AND 10   (2 rows)
    }

    if ($max_price!='') {
        $query .= " OR (total_price BETWEEN $max1 AND $max2)";
        //SELECT * FROM add_projects1 WHERE property='3' AND total_price BETWEEN 5 AND 10 OR (total_price BETWEEN 10 AND 15) 3 rows
    }

    if ($location!=''){
       $query .= " AND (project_location='$location')";
    }

    $sql = mysql_query($query);

    /* while($rlt=mysql_fetch_assoc ($sql)) {
         $row= $rlt['project_title'].'//';
    }*/

    $count = mysql_num_rows($sql);

    if ($count > 0) {
        while ($row=mysql_fetch_assoc($sql)) {
            $project_id = $row['project_id'];
            $row['project_location'] = Get_project_location($row['project_location']);
            $row['property'] = Get_property($row['property']);

            /* Here I want to get min price of floor_plan table condition project_id = "$project_id"
            $min = mysql_query("SELECT id,price FROM floor_plan WHERE project_id='2' order by price ASC LIMIT 1 ");

            while($mp=mysql_fetch_assoc($min)){
                $row['floor_min'] =$mp["price"];
            }*/

            $data[] = $row;
        }

        $buy_type = array("status"=>1,"count" =>$count,"data" =>$data);
        echo $buy_type = json_encode($buy_type);
    } else {
        $buy_type = array("status"=>0,"count" =>0,"data" =>"");
        echo $buy_type = json_encode($buy_type);
    }
?>

0 个答案:

没有答案