Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok. I worked it out with help of mac_gyver (php freaks). All calculations are done as i wish. My code below:</p> <pre><code>&lt;? include "connectdb.php"; $driver = 5; $datestamp = '2013/05/07'; $result2 = mysql_query("SELECT * FROM drivers WHERE id='$driver' LIMIT 1") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $lon=$row2['lon']; $lat=$row2['lat']; } $result = mysql_query("SELECT * FROM quotedb WHERE moveday='$datestamp' AND driver='$driver' AND cleared='Not Cleared' AND status='Done' ORDER BY moveday, timeday") or die(mysql_error()); $distance = 0; // accumulate the distance $first_pass = true; // flag to detect the first row inside the loop while($row = mysql_fetch_assoc( $result )) { $lon2a=$lon2; $lat2a=$lat2; $lon1=$row['lon1']; $lat1=$row['lat1']; $lon2=$row['lon2']; $lat2=$row['lat2']; // calculate the distance from the Garage to the first point of the first row if($first_pass){ $distance += (3958*3.1415926*sqrt(($lat-$lat1)*($lat-$lat1) + cos($lat/57.29578)*cos($lat1/57.29578)*($lon-$lon1)*($lon-$lon1))/180); $first_pass = false; } // calculate the distance for each row (segment) in the route $distance += (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); if ( $lon2a == "" or $lat2a =="" ) { } else { // calculate the distance from the second point of the first row to the first point of the next row $distance += (3958*3.1415926*sqrt(($lat2a-$lat1)*($lat2a-$lat1) + cos($lat2a/57.29578)*cos($lat1/57.29578)*($lon2a-$lon1)*($lon2a-$lon1))/180); } } // calculate the distance from the second point of the last row to the Garage $distance += (3958*3.1415926*sqrt(($lat2-$lat)*($lat2-$lat) + cos($lat2/57.29578)*cos($lat/57.29578)*($lon2-$lon)*($lon2-$lon))/180); echo "$distance&lt;br&gt; "; ?&gt; </code></pre> <p>Still think there is a place for improvement in the code. Will aplay Haversine method for calculations. Do you guys have some suggestion to improve this piece of code ... thx</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload