Forum Moderators: buckworks
you'll need the database of postcodes, sticky me for a link to the sql file but the table should go something like:
Pcode, Grid_N, Grid_E
BD1 416300 433300
LE7 463000 309300
whack this in a php file:
<?php // Connect to the database server
$dbcnx = mysql_connect("localhost",
"user", "password");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time (this is a host connect problem).</P>" );
exit();
}
// Select the database
if (! mysql_select_db("dbasename", $dbcnx) ) {
echo( "<P>Unable to locate the " .
"database at this time(this is a dbconnect problem).</P>" );
exit();
}
function calc_postcode_seperation($pcodeA,$pcodeB)
{
// PCODE A
$result=mysql_query("SELECT * FROM postcodes WHERE Pcode='$pcodeA' 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 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,2).'kms';
return $text;
}
echo calc_postcode_seperation('LE7','BD1');
?>
Hope that is of some help to people
hughie