Sounds like it'd be a lot easier to let MySQL do the calculation and 
sorting.

  $userLatitude = 50;
  $userLongitude = 70;
  $sql = "select companyname, blah, blah, 
     ceiling(sqrt(pow(69.1 * (latitude - $userLatitude), 2) +
     pow(53 * (longitude - $userLongitude), 2))) as distance
     from mytable order by distance";

miguel

On Thu, 18 Apr 2002, Mike Mike wrote:
> Here's what i'm working with.
> I'm figuring the distance between to points based on
> latitude and longitude.
> 
> while ($row = mysql_fetch_array($result))
> {
>       //calculate distance between the two cities.
>       $Lat2 = $row["Latitude"]; 
>       $Lon2 = $row["Longitude"]; 
>       $x = 69.1 * ($Lat2 - $Lat1);
>       $y = 53 * ($Lon2 - $Lon1);
>       
>       $Distance = sqrt($x * $x + $y * $y);
>       $Distance = ceil($Distance);
> 
>        if ($Distance < 100){
>               echo $row["CompanyName"]."<br>";
>               echo $row["Address"]."<br>";
>               echo $row["City"]."<br>";
>               echo $row["State"]."<br>";
>               echo $row["ZipCode"]."<br>";
>               echo $row["PhoneNumber"]."<br>";
>               echo $row["FaxNumber"]."<br>";
>               
>               echo "Approximant Distance = $Distance
> Miles<br><br>";
> }
> }
> Here is where my question comes to play.  How do I
> sort the $Distance so that 4 Miles will come up first
> 10 second 30 third ext..
> I have tried useing sort() function but it doesn't
> work quite the way I want it to.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to