Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:39:06+00:00 2026-06-09T21:39:06+00:00

I have a website where users can look up other users. It is a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:39:07+00:00Added an answer on June 9, 2026 at 9:39 pm

    EDIT: The thing is to calculate the distance directly in your select statement and to order the result based on this calculation.

    So if you stored the latitude/longitude in the database, you should be able to do something like that:

    $lat = {CURRENT_USER_LATITUDE};
    $long = {CURRENT_USER_LONGITUDE};
    SELECT users.*,
    6371 * 2 * ASIN(SQRT( POWER(SIN(($lat - ABS(users.latitude)) * pi()/180 / 2), 2) + COS($lat * pi()/180 ) * COS( ABS(users.latitude) * pi() / 180 ) * POWER(SIN(($long - users.longitude)*pi()/180 / 2),2))) AS distance
    FROM users
    ORDER BY distance
    

    And you might have a much simpler query if you’re using the geo data types in MySQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website where users can purchase tickets, but ticket quantities are usually
I want to create a website with various users. The users can have different
So, I have a user driven website. Users can post whatever they want, even
I have website where users can login with their Facebook account. I am using
I have a website and right now users can just open a directory and
I have a website for dance academy where Users can register and add/drop dance
I have a contact form on my website so users can send me an
I have multiple themes on my website and users can just switch between multiple
I'm using jax-rs (jersey) to create a website / web-service that other users can
I have a website where people can contact each other, and quite often people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.