Copy link to clipboard
Copied
'm trying to find the miles from km
Everything I try will give me the wrong outcome:
<?php
function calc_postcode_seperation($pcodeA,$pcodeB)
{
// PCODE A
$result=mysql_query("SELECT * FROM postcodes WHERE Pcode='$_REQUEST[postcode]' LIMIT 1");
$row=mysql_fetch_array($result);
$gridn[0]=$row[Grid_N];
$gride[0]=$row[Grid_E];
// PCODE B
$result=mysql_query("SELECT * FROM postcodes LEFT JOIN cars_agents ON postcodes.Pcode = cars_agents.postcode WHERE Pcode='$pcodeB' LIMIT 1");
$row=mysql_fetch_array($result);
$gridn[1]=$row[Grid_N];
$gride[1]=$row[Grid_E];
// TAKE GRID REFS FROM EACH OTHER.
$distance_n=$gridn[0]-$gridn[1];
$distance_e=$gride[0]-$gride[1];
// CALCULATE THE DISTANCE BETWEEN THE TWO POINTS
$hypot=sqrt(($distance_n*$distance_n)+($distance_e*$distance_e));
$text.='Distance between '.$pcodeA.' and '.$pcodeB.' is: '.round($hypot/1000*0.6214/100,2).' Miles Approx';
return $text;
}
//echo calc_postcode_seperation('B7','B21');
?>
Copy link to clipboard
Copied
Have you tried -
(($hypot/1000)*(0.6214/100,2)). should 100,2 be 100.2?
Copy link to clipboard
Copied
Hi,
Even tried that, it still comes up with 3 Miles.
Wolverhampton to Birmingham is not 3 miles
Its about 19-20 miles