<!-- Monthly Stats -->
<table>
  <tr><td colspan="6" class="head">Monthly Statistics</td></tr>
  <tbody>
    <tr>
      <td class="firstcol"><b>Month</b>
<?php
	$month_limit = 3;
	if (isset($_GET["month"])) {
		$month_limit = $_GET["month"];
	}
	if ($month_limit == 13) {
		echo "<a href=\"" . $this_document . "?month=6$options\">[-]</a> ";
	}
	if ($month_limit == 6) {
		echo "<a href=\"" . $this_document . "?month=3$options\">[-]</a> ";
		echo "<a href=\"" . $this_document . "?month=13$options\">[+]</a>";
	}
	if ($month_limit == 3) {
		echo "<a href=\"" . $this_document . "?month=6$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(convert_tz(time, 'UTC', '$tz') ,'%M %D') AS dbtime, DATE_FORMAT(convert_tz(time, 'UTC', '$tz'), '%M %Y') AS mt, DATE_FORMAT(convert_tz(time, 'UTC', '$tz'), '%Y%m') 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(convert_tz(time, 'UTC', '$tz')), MONTH(convert_tz(time, 'UTC', '$tz')) ORDER BY -time LIMIT $month_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('plots/temp_" . $row["mt_file"] . ".png','graph_window','resizable,scrollbars=no,width=768,height=288,left=100,top=100'))\">" . $row["mt"]  . "</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>";
?>

<p> </p>

<!-- Monthly plot -->
<TABLE>
 <TBODY>
  <TR><TD><IMG src="<?php print $month_plot ?>" alt="Temperature this month"></TD></TR>
</TBODY>
</TABLE>