I have a table of users that I want other users to be able to search for each other by name. Generally this is easy to a point. However I want users with similar names to show up in order of proximity from one another so lets say therotically I am searching for “Mike” but I don’t know his last name.. What I want my results to show is all the “Mike”‘s in my database starting with the closest one first. I have longitude/latitude for all my users so thats not a problem the problem is the way my query is currently constructed I have to provide a specific range. So I am trying to figure out if theres another way I can construct the query to have no range specified so it will just go from closest to furthest.
Current query looks like
SELECT *,(((acos(sin(($lat*pi()/180)) * sin((`latitude`*pi()/180))+cos(($lat*pi()/180)) * cos((`latitude`*pi()/180)) * cos((($lon - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance` FROM `memb_geo_locations` HAVING `distance` < $range ORDER BY `distance` ASC"
the flip side to this is also I am likely going to have to form an INNER JOIN with this as the names I’d be searching for are under a different table. where a member_id is the link between the 2 tables. the other table would have
member_id, firstname, lastname
the geo table has
member_id, longitude, latitude, primary
Any idea’s?
For the first part of your question just remove the HAVING and ORDER BY DESCending.
Adding the join should be straightforward enough: