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