Reputation: 231
I have a mysql table like below
userid zip
3 1000
4 1001
5 1002
6 1003
I want to show users nearby the login users. Consider one of the login user's userid is 5, I want to show the results like below. ie showing userid other than the login user's userid and sort the nearest zipcode first.
userid zip
6 1003
4 1001
3 1000
Upvotes: 1
Views: 47
Reputation: 45
You can use
select usersid,zip from users_location(name of your table )where userid!=(your user id) order by ZIP DESC
Upvotes: 1
Reputation:
if your zip stays the same, just substring to return those with a final character +/- 1/2/3 from your postcode
where zipcode != 'yourzip' AND zipcode like ('xxx%')
would return many similar, you could then add a column where you do zipcode-yourzip and order by this field. so you'd get some proximity information.
Upvotes: 1