advancedfuture Posted June 24, 2008 Share Posted June 24, 2008 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? Quote Link to comment Share on other sites More sharing options...
advancedfuture Posted June 24, 2008 Author Share Posted June 24, 2008 Never Mind! figured out the query all by myself 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.