<!-- Yearly Stats -->
<table>
  <tr><td colspan="6" class="head">Yearly Statistics</td></tr>
  <tbody>
    <tr>
      <td class="firstcol"><b>Year</b>
<?php
	$year_limit = 3;
	if (isset($_GET["year"])) {
		$year_limit = $_GET["year"];
	}
	if ($year_limit == 5) {
		echo "<a href=\"" . $this_document . "?year=3$options\">[-]</a>";
	}
	if ($year_limit == 3) {
		echo "<a href=\"" . $this_document . "?year=5$options\">[+]</a>";
	}

?>
	  </td>

      <td class="nextcol"><b>T<sup>min</sup> <?php print $deg_unit;?></b></td>
      <td class="nextcol"><b>T<sup>max</sup> <?php print $deg_unit;?></b></td>
      <td class="nextcol"><b>Mean <?php print $deg_unit;?></b></td>
      <td class="nextcol"><b>&sigma;</b></td>
      <td><b>n</b></td>

    </tr>
<?php
$query = "SELECT id, DATE_FORMAT(time,'%M %D') AS dbtime, DATE_FORMAT(time,'%Y') AS year, DATE_FORMAT(time,'%Y') AS mt_file, ROUND(max($t_corr),1) AS max, ROUND(min($t_corr),1) AS min, ROUND(SUM($t_corr)/COUNT(*),1) AS mean, COUNT(*) as count, ROUND(STDDEV($t_corr) * 100, 0) AS err FROM $table GROUP BY YEAR(time) ORDER BY -time LIMIT $year_limit";

$DB =  mysql_connect($DBHOST, $DBUSER, $DBPASS);
mysql_select_db($DBNAME, $DB);
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
        echo "\t<tr class=\"row\"><td><a href=\"javascript:void(window.open('$plotdir/temp_" . $row["year"] . ".png','graph_window','resizable,scrollbars=no,width=768,height=288,left=100,top=100'))\">" . $row["year"]  . "</a></td>";
        echo " <td> " . $row["min"] . "</td>";
        echo " <td> " . $row["max"] . "</td>";
        echo " <td> " . $row["mean"] . "</td>";
        echo " <td> " . $row["err"] . "% </td>";
        echo " <td> " . $row["count"] . "</td></tr>\n";
}
print "</table>";
?>