简体   繁体   English

PHP MySQL Query忽略AND语句

[英]PHP MySQL Query ignores AND statement

I have the following PHP query that executes a MySQL query without error but is ignoring the city portion of the query at the end? 我有以下PHP查询执行MySQL查询没有错误但忽略了查询的城市部分? Is there a way I have to arrange the AND/OR statements? 有没有办法安排AND / OR语句?

$sql_query = "SELECT ListOfficeMLSID AS list_office_mlsid, MLSNumber AS mls_number, City AS city, ListPrice AS list_price FROM my_table WHERE ListOfficeMLSID =\"office6\" OR ListOfficeMLSID =\"office7\" OR ListOfficeMLSID =\"office2\" AND ListPrice >= 1500000 AND city = \"Bonita Springs\" OR city = \"Estero\"";
$sql_query = "SELECT ListOfficeMLSID AS list_office_mlsid, MLSNumber AS mls_number, City AS city, ListPrice AS list_price FROM my_table WHERE ListOfficeMLSID IN('office6','office7','office2') AND ListPrice >= 1500000 AND city IN('Bonita Springs', 'Estero')";
$sql_query = "SELECT ListOfficeMLSID AS list_office_mlsid, MLSNumber AS mls_number, City AS city, ListPrice AS list_price FROM my_table WHERE (ListOfficeMLSID =\"office6\" OR ListOfficeMLSID =\"office7\" OR ListOfficeMLSID =\"office2\") AND ListPrice >= 1500000 AND (city = \"Bonita Springs\" OR city = \"Estero\")";

As I understand you want to get record that has ListOfficeMLSID in (office2, office6 or office6) AND ListPrice >= 1500000 AND city in(Bonita Springs or Estero)? 据我所知,你想得到(office2,office6或office6)和ListPrice> = 1500000 AND城市(Bonita Springs或Estero)的ListOfficeMLSID记录?

Your query will return records that suits at least one of your conditions 您的查询将返回至少符合您的一个条件的记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM