Well I am pleased to report in just under one week I have managed to achieve what I set out to do, thanks to you guys help and ideas.
I'm not much of a programmer, but I was able to pull data from the database I already had set up and was able to put it into a table for display with support of cumulus webtags for today's data.
In fact, I was able to create it so with a change of a number, the amount of data to be displayed can be changed. Originality I set out to display just 7 days of data, but I have decided to use a 30 day rolling view on my site too.
The programming displays an average for the X number of days displayed and also indicates the trending difference on the previous X number of days.
The 7 day table displays 210 different data numbers over 21 categories.
I've learned a lot in doing this and it has been a help with my knowledge of PHP and SQL. I am sure there are be much better ways to program this PHP script than the way I have done. I have added the PHP code to this post for others to use if they like; I have used a lot of other peoples' scripts and code over the years so it is nice to give a little back.
Code: Select all
<?php
//Include cumulus web tags file for "Today's" data
include_once("../cumuluswebtags.php"); ?>
<?php
//Include settings file OR hard code them into this page with the commented out settings below
include ('db_settings_details.php');
/*
$servername = "localhost"; // The server host name running MySQL database
$username = ""; // The username used to log-in to your database server
$password = ""; // The password used to log-in to your database server
$dbname = ""; // The name of the MySQL database we will store the tables in
$dbtable = "daydata"; // The name of the table being accessed
*/
// Set the period to be displayed
$dbrecordqty = "7"; // Set the number of records to display
$dbrecordqtytweek = $dbrecordqty *2; // Used for averaging. Set the number of records to compare against. Usually 2x the displayed data
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<style>
.rollingaverage {
border:1px solid #C0C0C0;
border-collapse:collapse;
border:2px solid #8f8f8f;
white-space: nowrap;
font-family: Verdana, arial, Arial, Helvetica, Verdana, sans-serif;
font-size: 10pt;
color: #333333;
}
.rollingaverage th {
border:1px solid #C0C0C0;
background:#F0F0F0;
font-family: Verdana, arial, Arial, Helvetica, Verdana, sans-serif;
font-size: 10pt;
color: #333333;
}
.rollingaverage td {
border:1px solid #C0C0C0;
font-family: Verdana, arial, Arial, Helvetica, Verdana, sans-serif;
font-size: 10pt;
color: #333333;
}
caption {
font-size: 1em;
font-style: normal;
font-weight: bold;
letter-spacing: .1em;
padding-top: 0.5em;
padding-bottom: 0.25em;
text-align: left;
}
</style>
<table class="rollingaverage"> <caption>Rolling <?php echo "$dbrecordqty"; ?> Day Data</caption>
<th style="border-bottom:2px solid #8f8f8f;">Data</th>
<th style="border-right:2px solid #8f8f8f; border-bottom:2px solid #8f8f8f;">Unit</th>
<th style="border-bottom:2px solid #8f8f8f;">Today<sup>*</sup></th>
<?php
//Get date from database. Limit to X entries for the weekly table
$sql = "SELECT LogDate FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$date_old = $row["LogDate"];
//Format date for display
$dateformatted = date ('d/m/y', strtotime($date_old));
$dayformatted = date ('D', strtotime($date_old));
//Output data for display
echo "<th style='border-bottom:2px solid #8f8f8f;'>" . $dayformatted. "<br/>" . $dateformatted. "</th>";
}
?>
<th style='border-left:2px solid #8f8f8f; border-bottom:2px solid #8f8f8f;'><?php echo "$dbrecordqty"; ?> Day<br/>Average<sup>*</sup></th>
<th style="border-bottom:2px solid #8f8f8f;">Trend on <br/>previous <br/><?php echo "$dbrecordqty"; ?> days<sup>*</sup></th>
</tr>
</thead>
<tbody>
<tr>
<td>High Temperature</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$tempTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT MaxTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["MaxTemp"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT MaxTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["MaxTemp"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT MaxTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["MaxTemp"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Low Temperature</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$tempTL"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT MinTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["MinTemp"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT MinTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["MinTemp"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT MinTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["MinTemp"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>High Apparent Temp.</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$apptempTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighAppTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["HighAppTemp"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighAppTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighAppTemp"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighAppTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighAppTemp"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Low Apparent Temp.</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$apptempTL"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT LowAppTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["LowAppTemp"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT LowAppTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["LowAppTemp"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT LowAppTemp FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["LowAppTemp"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Low Wind Chill</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$wchillTL"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT LowWindChill FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["LowWindChill"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT LowWindChill FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["LowWindChill"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT LowWindChill FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["LowWindChill"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>High Heat Index</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$heatindexTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighHeatind FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["HighHeatind"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighHeatind FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighHeatind"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighHeatind FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighHeatind"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>High Dew Point</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$dewpointTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighDewPoint FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["HighDewPoint"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighDewPoint FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighDewPoint"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighDewPoint FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighDewPoint"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Low Dew Point</td>
<td style="border-right:2px solid #8f8f8f;">°C</td>
<td><?php echo "$dewpointTL"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT LowDewPoint FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["LowDewPoint"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT LowDewPoint FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["LowDewPoint"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT LowDewPoint FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["LowDewPoint"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td style="border-top:2px solid #8f8f8f;">High Humidity</td>
<td style="border-top:2px solid #8f8f8f; border-right:2px solid #8f8f8f;">%</td>
<td style="border-top:2px solid #8f8f8f;"><?php echo "$humTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighHum FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td style='border-top:2px solid #8f8f8f;'>" .$row["HighHum"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighHum FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighHum"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;border-top:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighHum FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighHum"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green;border-top:2px solid #8f8f8f;'>+" .$trend. "</td>";}
else {echo "<td style='color:red;border-top:2px solid #8f8f8f;'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Low Humidity</td>
<td style="border-right:2px solid #8f8f8f;">%</td>
<td><?php echo "$humTL"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT LowHum FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["LowHum"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT LowHum FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["LowHum"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT LowHum FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["LowHum"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td style="border-top:2px solid #8f8f8f;">Rainfall</td>
<td style="border-top:2px solid #8f8f8f; border-right:2px solid #8f8f8f;">mm</td>
<td style="border-top:2px solid #8f8f8f;"><?php echo "$rfall"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT TotRainFall FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td style='border-top:2px solid #8f8f8f;'>" .$row["TotRainFall"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT TotRainFall FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["TotRainFall"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;border-top:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT TotRainFall FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["TotRainFall"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green;border-top:2px solid #8f8f8f;'>+" .$trend. "</td>";}
else {echo "<td style='color:red;border-top:2px solid #8f8f8f;'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td style="border-top:2px solid #8f8f8f;">Max Wind Gust</td>
<td style="border-top:2px solid #8f8f8f; border-right:2px solid #8f8f8f;">km/h</td>
<td style="border-top:2px solid #8f8f8f;"><?php echo "$wgustTM"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighWindGust FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td style='border-top:2px solid #8f8f8f;'>" .$row["HighWindGust"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighWindGust FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighWindGust"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;border-top:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighWindGust FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighWindGust"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green;border-top:2px solid #8f8f8f;'>+" .$trend. "</td>";}
else {echo "<td style='color:red;border-top:2px solid #8f8f8f;'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Max Average Speed</td>
<td style="border-right:2px solid #8f8f8f;">km/h</td>
<td><?php echo "$windTM"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighAvgWSpeed FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["HighAvgWSpeed"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighAvgWSpeed FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighAvgWSpeed"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighAvgWSpeed FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighAvgWSpeed"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Wind Run</td>
<td style="border-right:2px solid #8f8f8f;">km</td>
<td><?php echo "$windrun"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT TotWindRun FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["TotWindRun"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT TotWindRun FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["TotWindRun"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT TotWindRun FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["TotWindRun"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Wind bearing</td>
<td style="border-right:2px solid #8f8f8f;">°</td>
<td><?php echo "$domwindbearing"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT DomWindDir FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["DomWindDir"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT DomWindDir FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["DomWindDir"];
}
$calcaverage = $calcaverage / $dbrecordqty;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT DomWindDir FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["DomWindDir"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
echo "<td>" .number_format((float)$lastweekaverage, 1, '.', ''). "</td>";
?>
</tr>
<tr>
<td>Wind Direction</td>
<td style="border-right:2px solid #8f8f8f;">-</td>
<td><?php echo "$domwinddir"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HwindGBear FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["HwindGBear"]. "</td>";
}
?>
<td style="border-left:2px solid #8f8f8f;">
<?php
if ($calcaverage >=0 && $calcaverage <11.25){echo "N";}
if ($calcaverage >11.25 && $calcaverage <33.75){echo "NNE";}
if ($calcaverage >33.75 && $calcaverage <56.25){echo "NE";}
if ($calcaverage >56.25 && $calcaverage <78.75){echo "ENE";}
if ($calcaverage >78.75 && $calcaverage <101.25){echo "E";}
if ($calcaverage >101.25 && $calcaverage <123.75){echo "ESE";}
if ($calcaverage >123.75 && $calcaverage <146.25){echo "SE";}
if ($calcaverage >146.25 && $calcaverage <168.75){echo "SSE";}
if ($calcaverage >168.75 && $calcaverage <191.25){echo "S";};
if ($calcaverage >191.25 && $calcaverage <213.75){echo "SSW";}
if ($calcaverage >213.75 && $calcaverage <236.25){echo "SW";}
if ($calcaverage >236.25 && $calcaverage <258.75){echo "WSW";}
if ($calcaverage >258.75 && $calcaverage <281.25){echo "W";}
if ($calcaverage >281.25 && $calcaverage <303.75){echo "WNW";}
if ($calcaverage >303.75 && $calcaverage <326.25){echo "NW";}
if ($calcaverage >326.25 && $calcaverage <348.75){echo "NNW";}
if ($calcaverage >348.75 && $calcaverage <371.25){echo "N";}
?>
</td>
<td>
<?php
if ($lastweekaverage >=0 && $lastweekaverage <11.25){echo "N";}
if ($lastweekaverage >11.25 && $lastweekaverage <33.75){echo "NNE";}
if ($lastweekaverage >33.75 && $lastweekaverage <56.25){echo "NE";}
if ($lastweekaverage >56.25 && $lastweekaverage <78.75){echo "ENE";}
if ($lastweekaverage >78.75 && $lastweekaverage <101.25){echo "E";}
if ($lastweekaverage >101.25 && $lastweekaverage <123.75){echo "ESE";}
if ($lastweekaverage >123.75 && $lastweekaverage <146.25){echo "SE";}
if ($lastweekaverage >146.25 && $lastweekaverage <168.75){echo "SSE";}
if ($lastweekaverage >168.75 && $lastweekaverage <191.25){echo "S";};
if ($lastweekaverage >191.25 && $lastweekaverage <213.75){echo "SSW";}
if ($lastweekaverage >213.75 && $lastweekaverage <236.25){echo "SW";}
if ($lastweekaverage >236.25 && $lastweekaverage <258.75){echo "WSW";}
if ($lastweekaverage >258.75 && $lastweekaverage <281.25){echo "W";}
if ($lastweekaverage >281.25 && $lastweekaverage <303.75){echo "WNW";}
if ($lastweekaverage >303.75 && $lastweekaverage <326.25){echo "NW";}
if ($lastweekaverage >326.25 && $lastweekaverage <348.75){echo "NNW";}
if ($lastweekaverage >348.75 && $lastweekaverage <371.25){echo "N";}
?>
</td>
</tr>
<tr>
<td style="border-top:2px solid #8f8f8f;">High Pressure</td>
<td style="border-top:2px solid #8f8f8f; border-right:2px solid #8f8f8f;">hPa</td>
<td style="border-top:2px solid #8f8f8f;"><?php echo "$pressTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT MaxPress FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td style='border-top:2px solid #8f8f8f;'>" .number_format((float)$row["MaxPress"], 1, '.', ''). "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT MaxPress FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["MaxPress"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;border-top:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT MaxPress FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["MaxPress"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green;border-top:2px solid #8f8f8f;'>+" .$trend. "</td>";}
else {echo "<td style='color:red;border-top:2px solid #8f8f8f;'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Low Pressure</td>
<td style="border-right:2px solid #8f8f8f;">hPa</td>
<td><?php echo "$pressTL"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT MinPress FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .number_format((float)$row["MinPress"], 1, '.', ''). "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT MinPress FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["MinPress"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT MinPress FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["MinPress"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td style="border-top:2px solid #8f8f8f;">Sun Hours</td>
<td style="border-top:2px solid #8f8f8f; border-right:2px solid #8f8f8f;">hours</td>
<td style="border-top:2px solid #8f8f8f;"><?php echo "$SunshineHours"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HoursSun FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td style='border-top:2px solid #8f8f8f;'>" .$row["HoursSun"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HoursSun FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HoursSun"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;border-top:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HoursSun FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HoursSun"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green;border-top:2px solid #8f8f8f;'>+" .$trend. "</td>";}
else {echo "<td style='color:red;border-top:2px solid #8f8f8f;'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>Solar Radiation</td>
<td style="border-right:2px solid #8f8f8f;">W/m<sup>2</sup></td>
<td><?php echo "$solarTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighSolarRad FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["HighSolarRad"]. "</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighSolarRad FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighSolarRad"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighSolarRad FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighSolarRad"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tr>
<td>UV Index</td>
<td style="border-right:2px solid #8f8f8f;">UVI</td>
<td><?php echo "$UVTH"; ?></td>
<?php
//Get date from database. Limit to X entries for the weekly table and display them all sequentially
$sql = "SELECT HighUV FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
//Output data for display
echo "<td>" .$row["HighUV"]. "0</td>";
}
?>
<?php
//Get date from database. Limit to X entries for the weekly table and average them to one data result
$sql = "SELECT HighUV FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqty;
$result = $conn->query($sql);
$calcaverage=0;
while($row = $result->fetch_assoc()) {
$calcaverage= $calcaverage + $row["HighUV"];
}
$calcaverage = $calcaverage / $dbrecordqty;
$trendthisweek= $calcaverage;
//Output data for display
echo "<td style='border-left:2px solid #8f8f8f;'>" .number_format((float)$calcaverage, 1, '.', ''). "</td>";
?>
<?php
//Get date from database. Get data for last X*2 days. Compare for trend from above average by creating an average.
$lastweekaverage = array(); // create a variable to hold the information
$sql = "SELECT HighUV FROM ". $dbtable ." ORDER BY LogDate DESC LIMIT ". $dbrecordqtytweek;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$lastweekaverage[] = $row["HighUV"];
}
//Now you have X*2 days worth of data, delete first X days to get last week before averaging. Then subtract "this week" from "last week"
$x = 0;
while($x != $dbrecordqty) {
unset($lastweekaverage[$x]);
$x++;
}
$lastweekaverage=(array_sum($lastweekaverage));
$lastweekaverage = $lastweekaverage/$dbrecordqty;
$trend = $trendthisweek - $lastweekaverage;
$trend = number_format((float)$trend, 2, '.', '');
//Check to see if positive or negative number and add a leading + and change colour accordingly
if ($trend>=0){echo "<td style='color:green'>+" .$trend. "</td>";}
else {echo "<td style='color:red'>" .$trend. "</td>";}
?>
</tr>
<tbody>
</table>
<sup>*</sup> Today's data set is incomplete. Averages and trends do not include today's data.
<?php
$conn->close();
?>