Jump to content

[SOLVED] Linking Tables - Radius Search - query help


advancedfuture

Recommended Posts

OK so I have been developing this website in which I list businesses for sale. And I've been working on a radius search feature. my database looks as follows. I have 2 tables.

 

First table 'businesses'

Fields:

 

businessName

businessAddress

businessCity

businessZip

 

 

Second Table I have a list of all us Cities / Zips / Lat Long

Fields:

 

id

zip_code

city

county

state_name

state_prefix

lat

long

 

 

now I've managed to use the code made by Barand do do distance calculations

 

SELECT * FROM cities
WHERE
    60 * 1.1515 * DEGREES(ACOS(SIN(RADIANS($cityXlat))
    * SIN(RADIANS(latitude)) +  COS(RADIANS($cityXlat))
    * COS(RADIANS(latitude)) * COS(RADIANS($cityXlong-longitude)))) <= 50

 

However, I only want to return results in the table 'businesses'. I'm assuming I have to link the tables, I was figuring by zip. But how would I construct the query to not only link the tables but only return results that exist in the table businesses within the specified range?

Link to comment
Share on other sites

Never Mind! figured out the query all by myself :D yaay!

 

SELECT * FROM businesses, zip_code WHERE businesses.businessZip = zip_code.zip_code AND 
    60 * 1.1515 * DEGREES(ACOS(SIN(RADIANS($cityXlat))
    * SIN(RADIANS(lat)) +  COS(RADIANS($cityXlat))
    * COS(RADIANS(lat)) * COS(RADIANS($cityXlong-lon)))) <= 50

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.