I have some code that works out the distance between two post codes, when I echo the results they come up in the order they are in the database. How do I get them to order by these new values, so the smallest one first.
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;
}
$sorter = "SELECT * FROM directory WHERE authorised = 'Y'";
$sorterResults = mysql_query($sorter);
while ($sorterRow = mysql_fetch_array ($sorterResults)){
$sortpostcode = $sorterRow["postcode"];
$sortid = $sorterRow["id"];
$dir1 = posted value from previous page
$checksortpost = substr("$sortpostcode",0,4);
$distancetocleanersort = calc_postcode_seperation("$dir1","$checksortpost");
echo "$distancetocleanersort<br>";
}
Is there any way of putting a function into the query?