I have a website where users can look up other users. It is a basic search feature, but I want the users' results to be location based. So maybe they search "David". The basic query for the would be
SELECT *
FROM users
where fname = 'David' or
lname= 'David'
ORDER BY distance ASC
The problem is that the distance has to be first calculated between each user and the searcher. How can I do this? Not asking to be shown how to calculate distance or anything, just how to logically solve this problem.