0

我有一个引发错误的 mysql 查询,我猜这是因为我明智地使用了“NOT IN”这个短语:

$sqlGetCountry = mysqli_query($link, "SELECT * FROM locations WHERE country='$country' AND CURTIME() > time AND '$state' NOT IN state ORDER BY time desc LIMIT 20");
$sqlNumCountry = mysqli_num_rows($sqlGetCountry);

我有一张包含城市、州和国家/地区的表格,我基本上是在尝试查找结果中没有给定州(在本例中为 $state,可能是德克萨斯、夏威夷等)的查询。我得到错误:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

有人有线索吗?

4

1 回答 1

2

您不能将表传递给in,但可以传递子查询:

SELECT  * 
FROM    locations 
WHERE   country='$country' 
        AND CURTIME() > time 
        AND '$state' NOT IN (select state from state)
ORDER BY 
       time desc 
LIMIT  20
于 2012-07-26T18:56:07.127 回答