0

I have two tables add_projects and floor_plan. In the second table project_id is common. After successfully selecting the results from the add_projects table (here I will get project_id) again I want to check the minimum price of floor_table WHERE project_id='$project_id'. I am trying as follows but I am not getting the min value. How do I do this?

add_projects db structurefloor_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);
    }
?>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sujini R
  • 29
  • 1
  • 1
  • 5
  • 1
    Can you tell us what goes wrong? Do you not get the value you want? Or do you get nothing at all? – Ben Hillier Dec 01 '16 at 15:23
  • 1
    If this is new code, please stop using the `mysql_*` functions. They were deprecated in PHP 5.5, which is so old it no longer even receives security updates, and completely removed in PHP 7. Instead, use PDO or `mysqli_*`. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Dec 01 '16 at 15:47
  • 1
    Your code is wide open to [SQL injection](https://en.wikipedia.org/wiki/SQL_injection) attacks. Once you've migrated to PDO or `mysqli`, please read about prepared statements and parameter binding. This is the only way to reliably protect yourself. – ChrisGPT was on strike Dec 01 '16 at 15:48

0 Answers0