1

I have a MySQL table locations (id, name, latitude, longitude) and another table loads (id,from_location_id, to_location_id).

On my php form I get the id for from_location and the id for to_location.

How can I suggest the loads near from_location that should be delivered near to_location (with a range about 100km on both start and and locations)?

Thank you!

EDIT

SELECT locations.id,
       SQRT( POW(111.2 * (latitude1 - {$from_coordinates['latitude']}), 2) + POW(111.2 * ({$from_coordinates['longitude']} - longitude1) * COS(latitude1 / 57.3), 2)) AS distance,
       loads.id
FROM locations
INNER JOIN loads ON loads.from_location = locations.id
HAVING distance < 100
ORDER BY distance
DESC LIMIT 5

The problem is that I don't know how to find loads that start from this region and should be delivered near the latitude and longitude of another location id. I'm begginer on stackoverflow, sorry for any inconveniece

Shadow
  • 33,525
  • 10
  • 51
  • 64
Ciprian
  • 11
  • 2
  • 1
    a `select` query, perhaps? show what you've attempted so far - we're not here to do your job for you. – Marc B Jan 22 '16 at 14:44
  • Possible duplicate of [How to efficiently find the closest locations nearby a given location](http://stackoverflow.com/questions/3922404/how-to-efficiently-find-the-closest-locations-nearby-a-given-location) – ArSeN Jan 22 '16 at 14:45
  • SELECT locations.id, SQRT( POW(111.2 * (latitude1 - {$from_coordinates['latitude']}), 2) + POW(111.2 * ({$from_coordinates['longitude']} - longitude1) * COS(latitude1 / 57.3), 2)) AS distance, loads.id FROM locations INNER JOIN loads ON loads.from_location = locations.id HAVING distance < 100 ORDER BY `distance` DESC LIMIT 5 The problem is that I don't know how to find loads that start from this region and should be delivered near the latitude and longitude of another location id. I'm begginer on stackoverflow, sorry for any inconveniece. – Ciprian Jan 22 '16 at 14:57

0 Answers0