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*0.6214,2).'miles';
$distance .=round($hypot/1000*0.6214,2);
return $distance;
}
This is my function.
And this is what is input to it:
calc_postcode_seperation("$dir1","$checkpost");
$dir1 is the post code that a user has searched with and $checkpost is the postcode for the record in the database.
The distance between the two is then worked out.
It's this distance that I need the results to be ordered by.
Obviously the function is called within the SELECT statement so it can use each of the post codes in the database and work them out with the post code the user has searched with.