gpt4 book ai didi

php - 允许用户找到半径内的其他用户

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

我目前有这个代码,它将所有信息保存到数据库中,但我希望能够允许用户使用他们的邮政编码进行搜索,以便只显示他们选择的半径内的结果,例如。 1 英里、2 英里等我不知道如何去做。

 <form action="addhobby.php" method="POST">
Type:<input type="radio" name="type" value="meetup" checked>Meetup
<input type="radio" name="type" value="chat" checked>Chat
<br />

Hobby:<input type="text" name="hobby" value=""><br />

Location:<input type="text" name="location" value=""><br />
Postcode:<input type="text" name="postcode"><br />

Starts: <input type="date" name="startdate"> <input type="time" name="starttime"><br />
Ends: <input type="date" name="enddate"> <input type="time" name="endtime"> <br />

Description: <input type="text" name="description"><br />


<input type="submit" name="submit" value="Create">

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

$sql="INSERT INTO activities (hobby, location, postcode, sdate, stime, edate, etime, description, type) VALUES
('$_POST[hobby]','$_POST[location]', '$_POST[postcode]', '$_POST[startdate]', '$_POST[starttime]', '$_POST[enddate]', '$_POST[endtime]', '$_POST[description]', '$_POST[type]' )";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header("location:profile.php");

mysql_close($con)
?>

最佳答案

如果可以使用 HTML5 Geolocation API 获取纬度和经度,为什么还要使用邮政编码?

您可以使用以下SQL语句:

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 5 ORDER BY distance;

您必须将 lat 替换为纬度,将 lng 替换为经度。要按公里而不是英里搜索,请将 3959 替换为 6371。

来源:https://developers.google.com/maps/articles/phpsqlsearch_v3

关于php - 允许用户找到半径内的其他用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28069204/

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