Not sure exactly what you're wanting to average but this will return the average flight time of all pireps filed:
Code:
<?php
/* Constants */
@define ("MYSQL_CONNECT_INCLUDE", "connect_db.php"); // MySQL database connection
/* Database connection */
include(MYSQL_CONNECT_INCLUDE);
$query_hours = "SELECT sum(time_to_sec(duration)) as duration_sum FROM reports WHERE fsacars_rep_url IS NOT NULL";
$result_hours = mysql_query($query_hours);
if (mysql_numrows($result_hours) > 0) {
$time1 = mysql_result($result_hours,0,"duration_sum");
$time2 = $time1 / 3600;
}
$query_pireps = "SELECT * FROM reports WHERE fsacars_rep_url IS NOT NULL";
$result = mysql_query($query_pireps);
$pireps = mysql_numrows($result);
$avg1 = $time2 / $pireps;
$avg = number_format ($avg1, 2, ".", "");
print "<font face=tahoma size=2><b>Average flight length:</b> $avg hrs.</font>";
/* Close the database connection */
mysql_close();
php?>
"WHERE fsacars_rep_url IS NOT NULL" keeps it from factoring in the dummy flights you've used to import a pilot's hours (providing you've set the fsacars_rep_url field to NULL for those flights). Otherwise your average flight length might return 100 hrs or more.
Here's the script in use:
http://www.cat-tamer.com/flightsim/f...per_flight.php
Jim
Bookmarks