gpt4 book ai didi

php - SQL 错误 : Every derived table must have its own alias

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:49 27 4
gpt4 key购买 nike

我知道有很多问题可以解决这个错误,但我已经完成了他们要求的内容来解决我认为的问题。以下是我所做的,但我仍然收到错误。此脚本的目标是显示特定半径内的所有邮政编码。

$zip = 94550; // "find nearby this zip code"
$radius = 15; // "search radius (miles)"
$maxresults = 10; // maximum number of results you'd like

$sql = "SELECT * FROM
(SELECT o.zipcode, o.city, o.state,
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.latitude-o.latitude)*0.017453293)/2),2) +
COS(z.latitude*0.017453293) *
COS(o.latitude*0.017453293) *
POWER(SIN(((z.longitude-o.longitude)*0.017453293)/2),2)
)))) AS distance
FROM zipcoords z,
zipcoords o,
zipcoords a
WHERE z.zipcode = ".$zip." AND z.zipcode = a.zipcode AND
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.latitude-o.latitude)*0.017453293)/2),2) +
COS(z.latitude*0.017453293) *
COS(o.latitude*0.017453293) *
POWER(SIN(((z.longitude-o.longitude)*0.017453293)/2),2)
)))) <= ".$radius."
ORDER BY distance)
ORDER BY distance ASC LIMIT 0,".$maxresults;

$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());

while ($ziprow = mysql_fetch_array($result)) {
$zipcode = $ziprow['zipcode'];
echo "$zipcode<br>";
}

我在数据库中的所有列都是 varchar。邮政编码是主要的,我会把它设为 INT,但它不允许在邮政编码的开头有 0。所以我将其更改为 varchar 并允许它。感谢您的帮助!

最佳答案

$sql = "SELECT * FROM
(SELECT o.zipcode, o.city, o.state,
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.latitude-o.latitude)*0.017453293)/2),2) +
COS(z.latitude*0.017453293) *
COS(o.latitude*0.017453293) *
POWER(SIN(((z.longitude-o.longitude)*0.017453293)/2),2)
)))) AS distance
FROM zipcoords z,
zipcoords o,
zipcoords a
WHERE z.zipcode = ".$zip." AND z.zipcode = a.zipcode AND
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.latitude-o.latitude)*0.017453293)/2),2) +
COS(z.latitude*0.017453293) *
COS(o.latitude*0.017453293) *
POWER(SIN(((z.longitude-o.longitude)*0.017453293)/2),2)
)))) <= ".$radius."
ORDER BY distance) AS random_word_to_silence_that_error
ORDER BY distance ASC LIMIT 0,".$maxresults;

我添加了 random_word_to_silence_that_error 因为在你的情况下我认为它不会有其他用途。

关于php - SQL 错误 : Every derived table must have its own alias,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18552203/

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