I am trying to build a quote system that quotes based off the distance from a delivery hub.
I have one table (table1) with all the postal codes and their corresponding long and lat in the country
I have another table (table2) with all my shipping hubs with their post codes and corresponding long and lat.
So when the user inputs their zip code I can get their long and lat from my database with this code:
$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare("SELECT name, lng, lat FROM posts WHERE code=:code");
$stmt->execute(['code' => $post1]);
while ($row = $stmt->fetch()) {
$lng1 = $row['lng'];
$lat1 = $row['lat'];
$name1 = $row['name'];
}
echo "name 1: ".$name1;
echo "<br>";
echo "post code 1: ".$lng1;
echo "<br>";
echo "post code 1: ".$lat1;
How do I use that long and lat to then find the closest hub in table 2?