0

I have two table one for users where user save their details as well as zip code and distance(required)

USERTABLE - Name, email, zip, distance.

and another table for zip_info to get latitude and longitude.

ZIPINFO - zipcode, latitude, longitude.

I have user search form where we need to enter zip code and distance. Now the searching result should include all the user whose have zip code is entered zip code, OR they have zip code that are under the radius of entered distance AND also need to check that if user distance radius(it means he will search only under specified distance radius from his zip code) is eligible for search.

Example- a user set his zip code-01960 and distance-50 miles

meaning we want to show this user for zip codes within 50 miles of 01960. So, this user should appear when searching zip code 01960 as well as nearby zipcodes like 01923, 01940 etc.

Now i will explain you in more detail-

User name 'A' set his zip code 134005 and distance - 100 miles (means this user will be search at zip code 134005 and all zip code that are under 100 miles of 134005(e.g 134004).

now I am trying to search a user let suppose Zip code - 134003 and distance is 50 miles. now all the users that are at zip code 134003 and under 50 miles of 134003 should return. Suppose that 134004 is under 50 miles of 134003 but 134005 is not?

According to my requirement user name 'A' should be return.

I want to create SQL query for searching result. Thanx in advance

Sachin Kumar
  • 3,001
  • 1
  • 22
  • 47
  • Are you working with current location ?i thing it will be easy if you also store the distance of each code by calculating distance in php ,you can refer this http://www.geodatasource.com/developers/php. – Bibhudatta Sahoo Jun 27 '17 at 10:30
  • No, I am not working on current location. Just put zip code and distance on my search form and return users. – Sachin Kumar Jun 27 '17 at 10:34
  • Okay then you can store the distance in our DB then compare that with your distance value. – Bibhudatta Sahoo Jun 27 '17 at 10:37
  • my application flow like this- each user has zip_code and distance field. (by distance field means that the user set his preferences that he will be searched under the radius of distance miles of his zip code). Now search form asked zip_code1 and distance1. if user preferences zip_codes lies under the radius of distance1 miles of zip_code1 then that user should return. – Sachin Kumar Jun 27 '17 at 10:49

0 Answers0