I am trying to sort the array $showall below. I put the $DISTANCE variable first and I want it to sort numerical not alphabetically. No matter what sort function I put in (asort, fsort, usort) it still displays the same. DISTANCE is not a field in my table, it is being calculated within the WHILE loop. What sort should I be using and where exactly should it go?
Thanks for any help on this.
$sql = "SELECT * FROM zipcodes WHERE
Latitude >= $minLat
AND Latitude <= $maxLat
AND Longitude >= $minLong
AND Longitude <= $maxLong GROUP BY ZIPCode";
if (!$result = mysql_query($sql)) {
//Error in mySQL query
print "There was an error in sql statement, ".mysql_error()."<br><b>$sql</b>";
exit;
}
else {
$zcdDistance = new DistanceAssistant;
$j=0;
while ($myrow = mysql_fetch_array($result)){
$Distance = $zcdDistance->Calculate($Latitude,$Longitude,$myrow["Latitude"],$myrow["Longitude"]);
if ($Distance <= $Miles){
$zip1= $myrow['ZIPCode'];
$city1= $myrow['CityName'];
$Distance = sprintf("%01.1f", $Distance);
$showall[$j] ="$Distance<td>$city1<td>$zip1<tr><td>";
$j++;
}
}
}
}
mysql_close($dbConn);
asort($showall);
for ($i = 0; $i < ($j-1); $i++) {
$display_it .="$showall[$i]";
}