gpt4 book ai didi

php - SQL 查询在 PHPMyAdmin 中运行良好,但不适用于 mysql_query

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:55 25 4
gpt4 key购买 nike

当我使用 PHPMyAdmin 运行以下 SQL 查询时,它工作得很好,但是当我从网页运行它时,出现错误。我在 StackOverflow 上四处寻找类似的问题,并尝试了他们的建议,但是唉......有没有人知道为什么它不能在网页上工作?

加入变量后的SQL查询(示例):

SELECT place FROM locations WHERE (( 69.1 * ( latitude - 51.4700000 ) ) * ( 69.1 * (latitude - 51.4700000 ) )) + ( ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 )) * ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 ) ) ) < 976.5625 ORDER BY ((69.1 * ( latitude - 51.4700000 ) ) * ( 69.1 * ( latitude - 51.4700000 ) )) + ( ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 ) ) * ( 69.1 * ( longitude - 5.5528000 ) * COS(51.4700000 / 57.3 ) ) ) ASC

PHP($radius 和 $start 在此之前定义了一点):

$latitude = $start['latitude'];
$longitude = $start['longitude'];
$r = pow($radius, 2);
$inrange = "SELECT place FROM locations_2 WHERE ((69.1 * (latitude - $latitude)) * (69.1 * (latitude - $latitude))) + ((69.1 * (longitude - $longitude) * COS($latitude / 57.3)) * (69.1 * (longitude - $longitude) * COS($latitude / 57.3))) < $r ORDER BY ((69.1 * (latitude - $latitude)) * (69.1 * (latitude - $latitude))) + ((69.1 * (longitude - $longitude) * COS($latitude / 57.3)) * (69.1 * (longitude - $longitude) * COS($latitude / 57.3))) ASC";
$result = mysql_query($inrange) or die(mysql_error());

我得到的错误信息是:

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 ')) * (69.1 * (`latitude` - ))) + ((69.1 * (`longitude` - ) * COS( / 57.3)) * (69' at line 1

更奇怪的是它有效...我把它全部写下来,就像我现在向您展示它的方式一样,很高兴看到它工作得很好。那是今天早些时候的事。大约一个小时前,我又试了一次,但由于某种原因它停止了工作。我真的不记得改变了什么。

编辑

谢谢大家。我想通了,结果证明我犯了一个愚蠢的错误。今天早些时候它起作用了,因为所有用户都设置了他们的位置。现在,我有一些用户在遍历他们时发现经度和纬度是空的。

最佳答案

从您的错误消息来看,$latitude$longitude 似乎不包含任何值。您可能想检查 $start 是否设置正确。这就是我能为您提供的所有帮助,因为我不知道 $start 是什么以及您如何获得它。

关于php - SQL 查询在 PHPMyAdmin 中运行良好,但不适用于 mysql_query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12557317/

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