gpt4 book ai didi

PHP MYSQL SELECT 查询卡在 WHERE 子句中的负值或语法上

转载 作者:行者123 更新时间:2023-11-29 14:24:58 24 4
gpt4 key购买 nike

有一个问题一直让我抓狂。我有将坐标传递给查询函数的代码。该查询适用于纬度(见下文),但不适用于经度。我对两者都有一个复杂的 WHERE 子句,但后来转移到单独的 WHERE 子句以便对两者进行故障排除。下面的代码显示了注释掉的纬度。如果我反转注释,纬度将按预期工作。引用数据库中的所有值都是 double 值,并且经度为负值,而纬度为正值。我一直在寻找不正确的语法,但找不到它。我什至有要传递的舍入变量、双重检查的列名称、反转运算符等等。两个WHERE分别相同;并且经度变量根据给定误差的反馈干净地传递。那么,沃尔多在哪里?谢谢!

错误:

Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long>=-93.497315 AND long<=-91.365967' at line 1

调用函数:

$box=$_GET["rect"];
$box=ltrim($box,"((");
$box=rtrim($box,"))");
$boxArray = explode("), (",$box);
$sw = explode(", ",$boxArray[0]);
$ne = explode(", ",$boxArray[1]);
$swLat = round($sw[0], 6);
$swLong = round($sw[1], 6);
$neLat = round($ne[0], 6);
$neLong = round($ne[1], 6);
$job_set = get_job_by_Rectangle($swLat, $swLong, $neLat, $neLong);

while ($job = mysql_fetch_array($job_set)) {
echo $job["projectFK"] . ", ";}

问题函数:

function get_job_by_Rectangle($swLat, $swLong, $neLat, $neLong) {
global $connection;
$query = "SELECT * ";
$query .= "FROM projcoords ";
//$query .= "WHERE lat>= " . $swLat . " AND lat<= " . $neLat . " " ;
$query .= " WHERE long>=" . $swLong . " AND long<=" . $neLong . " " ;
//$query .= " ORDER BY projectFK";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);

return $result_set;
}

最佳答案

LONGreserved word在 MySQL 中。

因此您需要用反引号引用列名称:

$query .= " WHERE `long`>=" . $swLong . " AND `long`<=" . $neLong . " " ;

关于PHP MYSQL SELECT 查询卡在 WHERE 子句中的负值或语法上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11173829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com