I have some code as follows for a find nearest feature using shops from a database: while ($row= mysql_fetch_array($result)) { $title = $row["shopname"]; $title1 = $row["phone"]; $title8 = $row["Easting"]; $title9 = $row["Northing"]; $dist1 = abs($customer_easting - $title8); $dist2 = abs($customer_northing - $title9); $dist1 = $dist1^2; $dist2 = $dist2^2; $distance_in_metres = $dist1 + $dist2; $distance_in_metres = $distance_in_metres^0.5; $distance_in_miles = $distance_in_metres/$constant; $distance_in_miles = number_format($distance_in_miles, 2); echo "$title1 , $distance_in_miles"; $count++ ; } PHP: How do I order this list by $distance_in_miles so that the shops are listed nearest first? many thanks.
It doesn't look to me like it's actually an array, but if you put it into an array, you can sort it with the normal sort() function.
you should use sort function - heres small demo: <?php $members = array("GuyFromChicago","rickbender1940","DigitalPoint"); sort($members); foreach($members as $val) { print "$val "; } ?> PHP: OUTPUT: DigitalPoint GuyFromChicago rickbender1940 For reverse, use rsort(). Mike
So how would I put the values of name, phone, easting, northing and distance into an array? I had thought that they were already in an array by using mysql_fetch_array.......
You could add a calculation in your mysql select query to calculate the distance_in_miles. Then you could either sort it by the calculated column in your select query (ORDER BY calculation) or use array_sort().