Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在SQL选择代码中更新筛选器_Php_Mysql_Sql_Subquery - Fatal编程技术网

Php 在SQL选择代码中更新筛选器

Php 在SQL选择代码中更新筛选器,php,mysql,sql,subquery,Php,Mysql,Sql,Subquery,我想在我编写的以下代码中更新a过滤器。我不知道该怎么说 代码是: $query = "SELECT P.`Building_info` as `name`,P.`Area` as `area`, avg( CASE WHEN P.`Bedroom`='4' THEN P.`$price` ELSE NULL

我想在我编写的以下代码中更新a过滤器。我不知道该怎么说

代码是:

$query = "SELECT  P.`Building_info` as `name`,P.`Area` as `area`,
            avg(
                CASE 
                    WHEN P.`Bedroom`='4' 
                    THEN P.`$price`
                    ELSE NULL 
                END
            ) AS 'Beds_4',
            avg(
                CASE 
                    WHEN P.`Bedroom`='5' 
                    THEN P.`$price`
                    ELSE NULL 
                END
            ) AS 'Beds_5'
        FROM    All_Rent P
        WHERE P.Building_info<>''
        AND Sale_Rent='$accom'
        AND converted_date > '$min_date'
        GROUP BY P.`Building_info`";
$query=“选择P.`Building\u info`作为`name`,P.`Area`作为`Area`,
平均值(
案例
当P.“卧室”='4'
然后P.“$price”`
否则无效
结束
)作为“床4”,
平均值(
案例
当P.“卧室”='5'
然后P.“$price”`
否则无效
结束
)作为“床位5”
从所有
其中P.Building_信息“
销售和租金=“$accom”
并转换为“$min\u date”
按“建筑信息”页分组;
我想在
Area=“Euston Road”
中添加一个过滤器,即仅选择名称为“Euston Road”的区域


有人能帮忙吗

假设您使用的变量$area的值为“Euston Road”,只需将查询更新为:

$query = "SELECT  P.`Building_info` as `name`,P.`Area` as `area`,
        avg(
            CASE 
                WHEN P.`Bedroom`='4' 
                THEN P.`$price`
                ELSE NULL 
            END
        ) AS 'Beds_4',
        avg(
            CASE 
                WHEN P.`Bedroom`='5' 
                THEN P.`$price`
                ELSE NULL 
            END
        ) AS 'Beds_5'
    FROM    All_Rent P
    WHERE P.Building_info<>''
    AND Sale_Rent='$accom'
    AND converted_date > '$min_date'
    AND P.`Area` = '$area'
    GROUP BY P.`Building_info`";
$query=“选择P.`Building\u info`作为`name`,P.`Area`作为`Area`,
平均值(
案例
当P.“卧室”='4'
然后P.“$price”`
否则无效
结束
)作为“床4”,
平均值(
案例
当P.“卧室”='5'
然后P.“$price”`
否则无效
结束
)作为“床位5”
从所有
其中P.Building_信息“
销售和租金=“$accom”
并转换为“$min\u date”
和P.`Area`='$Area'
按“建筑信息”页分组;

那么将其添加到
where
子句中?如果您不知道如何进行,那么您应该开始学习sql…您可能还想了解如何防止sql注入: