带有多个between子句的php到mysql查询未按预期工作

oknrviil  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(208)
$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')";

用实际值替换变量之间的第二个值将返回预期结果,但查询不能同时处理这两个变量。
回显$query1以确保已正确编写查询时:

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

所以我很有信心没有语法错误。
有什么问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题