Hi Friends I need help on this logic
Problem Definition:
There are 4 tables:
- Project
- Project Name
- Project Id
- Zipcode
- Vendor
- Vendor Id
- Vendor Name
- Phone
- Service area distance
- Vendor Service Areas
- Vendor Id
- Service area zipcode
- Zipcode Details
- zipcode
- latitude
- longitude
- Every project have one zipcode
- A vendor can have multiple service area zipcodes
When a vendor login, I am getting all the projects within vendor's service area.
Ex: If vendor has two zipcode in his service area 22032, 10031 and his service area distance is 20 Miles then all the project within these service area around 20 Miles.
I am calculating distance between project zipcode and vendor zipcodes and showing Minimum distance in a column
Ex: project zipcode 22032 and vendor zipcodes are 22031 and 22040:
22032 to 22031 = 3.01 miles
22032 to 22040 = 7.98 miles
Then Distance = 3.01
Problem: Now client want to SORT BY DISTANCE
My Try:
- I tried to do this with PHP arrays and object but with large data It is slow down the process
- I tried to calculate it from MYSQL distance calculation haversine formula, but not able to figure out
- I tried to map the distance in seperate table but there are too many zipcodes
Please suggest any logic which can take less time.