PHP到MySQL查询,多个between子句不能按预期工作

时间:2018-04-14 21:20:38

标签: php mysql between

$a = 51;
$b = 53;

$x = -2;
$y = 2;
$query1 = "SELECT * FROM Events WHERE (latitude BETWEEN '$a' AND '$b') 
        AND (longitude BETWEEN '$x' AND '$y')";

上面的查询检索没有结果,即使它应该。 奇怪的是以下查询工作:

 $query2 = "SELECT * FROM Events WHERE (latitude BETWEEN '$a' AND '$b') 
        AND (longitude BETWEEN '$x' AND 2)"; 

 $query3 = "SELECT * FROM Events WHERE (latitude BETWEEN '$a' AND '$b') 
        AND (longitude BETWEEN -2 AND '$y')";

用实际值替换第二个BETWEEN变量中的任何一个返回 预期成绩 但是查询不能同时使用这两个变量。

当回显$ query1以确保我已正确编写查询时:

  "SELECT * FROM Events WHERE (latitude BETWEEN '51' AND '53') 
        AND (longitude BETWEEN '-2' AND '2')"

所以我相信没有任何语法错误。

任何想法可能是什么问题?

0 个答案:

没有答案