Could someone help me get my top ten up and running? I have been struggling with it for several days and can't seem to get beyond the following error despite countless hours of research combined with trial and error attempts. Don`t like to give up, but my head hurts!
I realize that once this error is corrected, others may develop but at least that`s progress
Fatal error: Call to undefined function mysqli() in /var/sites/k/kerrentweather.ca/public_html/topten.php on line 274
Here is my topten php:
<?php
//----------------------------------------------------------------------
// Top 10's from a MySql database
// Author: Mark Crossley
//
// Ver 0.1 - 22/10/13 - Initial release, 0.X = a work in progress, breakages and changes on the fly likely!
// Ver 0.2 - 23/10/13 - Applied min-width:135px to all the main table <td>'s
// Ver 0.3 - 23/10/13 - Made the SQL table name a variable
// Ver 0.4 - 23/10/13 - Added IS NOT NULL to simpleHiLo query
// Ver 0.5 - 24/10/13 - Added wettest years (can also do driest)
// Ver 0.6 - 24/10/13 - Changed rain day threshold to cater for in/mm
// Ver 0.7 - 01/12/13 - Restructured to add category header rows
// - Added greatest/smallest temp & humidity ranges, heat/coolDegDays, smallest pressure range
// - Added execution times
// Ver 0.8 - 03/12/13 - Fixed MaxSolarRad
// Ver 0.9 - 04/12/13 - Added min MaxSolarRad (dull days)
// Ver 0.10 02/01/14 - Added highlighting of recent records
// Ver 0.11 12/01/14 - Fixed missing blank data cells in output
// Ver 0.12 07/02/14 - Added 'most/least rain days in a month', removed 'Driest Years'
// Ver 0.13 12/03/14 - Fixed a logic problem in the row/cell layout code
// Ver 0.14 10/11/14 - Added Frost days: Earliest, Latest, Most, Least
// Ver 0.15 02/02/15 - Ordered equal records by date ascending (oldest first)
//----------------------------------------------------------------------
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <
http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------
// Standard Source view option check
function check_sourceview () {
if (isset($_GET['view']) && ($_GET['view'] == 'sce' || $_GET['view'] == 'src')) {
$filenameReal = __FILE__;
$download_size = filesize($filenameReal);
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
header('Connection: close');
readfile($filenameReal);
exit;
}
}
// Just list the PHP source?
check_sourceview();
//include 'page_header_inc.php';
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$unitT = '°C';
$unitR = 'mm';
$unitRR = 'mm/h';
$unitW = 'mph';
$unitWR = 'miles';
$unitP = 'hPa';
// default rain day thresholds = 0.2mm or 0.01" - you may want to over-ride these values
$rainDayThreshold = ($unitR === 'mm' ? 0.2 : 0.01);
$dayFileTableName = 'dayfile';
$cells = 5; // number of data tables to row on the page
$recentHighlight = 32; // number of days (+1) of recent records to highlight
// Hidden MySQL read-only connection parameters
//include '../forbidden/db_ro_details.php';
// Create the page header - with embedded CSS to avoid a separate file (frowned on by some!)
?>
<style>
.cell1 {
text-align: right;
width: 40%;
}
table {
padding: 0px;
width: 100%;
}
table td {
font-size: 0.9em;
}
caption {
text-align: center;
border-bottom: #000;
border-bottom-width: thin;
border-bottom-style: solid;
}
.dataTable td {
padding-right: 4px;
padding-left: 4px;
vertical-align: bottom;
border-top: 0 !important;
background: transparent !important;
}
.header {
text-align: center;
font-size: 1.2em;
font-weight: bold;
border-bottom: #000;
border-bottom-width: thin;
border-bottom-style: solid;
border-top: #000;
border-top-width: thin;
border-top-style: solid;
color: #2EC0FF;
}
.cTempH {
background: #ffdddd; /* Old browsers */
background: -moz-linear-gradient(top, #ffdddd 14%, #c6c6ff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(14%,#ffdddd), color-stop(100%,#c6c6ff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffdddd 14%,#c6c6ff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffdddd 14%,#c6c6ff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffdddd 14%,#c6c6ff 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffdddd 14%,#c6c6ff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffdddd', endColorstr='#c6c6ff',GradientType=0 ); /* IE6-9 */
}
.cTempL {
background: #c6c6ff; /* Old browsers */
background: -moz-linear-gradient(top, #c6c6ff 0%, #ffdddd 86%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#c6c6ff), color-stop(86%,#ffdddd)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #c6c6ff 0%,#ffdddd 86%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #c6c6ff 0%,#ffdddd 86%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #c6c6ff 0%,#ffdddd 86%); /* IE10+ */
background: linear-gradient(to bottom, #c6c6ff 0%,#ffdddd 86%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c6c6ff', endColorstr='#ffdddd',GradientType=0 ); /* IE6-9 */
}
.cWindH {
background: #d2fdc7; /* Old browsers */
background: -moz-linear-gradient(top, #d2fdc7 0%, #f7f7f7 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#d2fdc7), color-stop(100%,#f7f7f7)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #d2fdc7 0%,#f7f7f7 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #d2fdc7 0%,#f7f7f7 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #d2fdc7 0%,#f7f7f7 100%); /* IE10+ */
background: linear-gradient(to bottom, #d2fdc7 0%,#f7f7f7 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d2fdc7', endColorstr='#f7f7f7',GradientType=0 ); /* IE6-9 */
}
.cWindL {
background: #f7f7f7; /* Old browsers */
background: -moz-linear-gradient(top, #f7f7f7 0%, #d2fdc7 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#d2fdc7)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f7f7f7 0%,#d2fdc7 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f7f7f7 0%,#d2fdc7 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f7f7f7 0%,#d2fdc7 100%); /* IE10+ */
background: linear-gradient(to bottom, #f7f7f7 0%,#d2fdc7 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#d2fdc7',GradientType=0 ); /* IE6-9 */
}
.cPressH {
background: #afffeb; /* Old browsers */
background: -moz-linear-gradient(top, #afffeb 0%, #f7f7f7 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#afffeb), color-stop(100%,#f7f7f7)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #afffeb 0%,#f7f7f7 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #afffeb 0%,#f7f7f7 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #afffeb 0%,#f7f7f7 100%); /* IE10+ */
background: linear-gradient(to bottom, #afffeb 0%,#f7f7f7 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#afffeb', endColorstr='#f7f7f7',GradientType=0 ); /* IE6-9 */
}
.cPressL {
background: #f7f7f7; /* Old browsers */
background: -moz-linear-gradient(top, #f7f7f7 0%, #afffeb 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#afffeb)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f7f7f7 0%,#afffeb 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f7f7f7 0%,#afffeb 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f7f7f7 0%,#afffeb 100%); /* IE10+ */
background: linear-gradient(to bottom, #f7f7f7 0%,#afffeb 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#afffeb',GradientType=0 ); /* IE6-9 */
}
.cHumH {
background: #f7f7f7; /* Old browsers */
background: -moz-linear-gradient(top, #f7f7f7 0%, #e0e0e0 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#e0e0e0)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f7f7f7 0%,#e0e0e0 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f7f7f7 0%,#e0e0e0 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f7f7f7 0%,#e0e0e0 100%); /* IE10+ */
background: linear-gradient(to bottom, #f7f7f7 0%,#e0e0e0 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#e0e0e0',GradientType=0 ); /* IE6-9 */
}
.cHumL {
background: #e0e0e0; /* Old browsers */
background: -moz-linear-gradient(top, #e0e0e0 0%, #f7f7f7 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#e0e0e0), color-stop(100%,#f7f7f7)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #e0e0e0 0%,#f7f7f7 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #e0e0e0 0%,#f7f7f7 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #e0e0e0 0%,#f7f7f7 100%); /* IE10+ */
background: linear-gradient(to bottom, #e0e0e0 0%,#f7f7f7 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e0e0e0', endColorstr='#f7f7f7',GradientType=0 ); /* IE6-9 */
}
.cSolarH {
background: #ffffb2; /* Old browsers */
background: -moz-linear-gradient(top, #ffffb2 0%, #f7f7f7 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffb2), color-stop(100%,#f7f7f7)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffb2 0%,#f7f7f7 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffb2 0%,#f7f7f7 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffb2 0%,#f7f7f7 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffb2 0%,#f7f7f7 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffb2', endColorstr='#f7f7f7',GradientType=0 ); /* IE6-9 */
}
.cSolarL {
background: #f7f7f7; /* Old browsers */
background: -moz-linear-gradient(top, #f7f7f7 0%, #ffffb2 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#ffffb2)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f7f7f7 0%,#ffffb2 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f7f7f7 0%,#ffffb2 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f7f7f7 0%,#ffffb2 100%); /* IE10+ */
background: linear-gradient(to bottom, #f7f7f7 0%,#ffffb2 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#ffffb2',GradientType=0 ); /* IE6-9 */
}
.cRainH {
background: #d6edfa; /* Old browsers */
background: -moz-linear-gradient(top, #d6edfa 0%, #f7f7f7 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#d6edfa), color-stop(100%,#f7f7f7)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #d6edfa 0%,#f7f7f7 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #d6edfa 0%,#f7f7f7 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #d6edfa 0%,#f7f7f7 100%); /* IE10+ */
background: linear-gradient(to bottom, #d6edfa 0%,#f7f7f7 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d6edfa', endColorstr='#f7f7f7',GradientType=0 ); /* IE6-9 */
}
.cRainL {
background: #f7f7f7; /* Old browsers */
background: -moz-linear-gradient(top, #f7f7f7 0%, #d6edfa 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#d6edfa)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f7f7f7 0%,#d6edfa 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f7f7f7 0%,#d6edfa 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f7f7f7 0%,#d6edfa 100%); /* IE10+ */
background: linear-gradient(to bottom, #f7f7f7 0%,#d6edfa 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#d6edfa',GradientType=0 ); /* IE6-9 */
}
.cDewL {
background: #eeccff; /* Old browsers */
background: -moz-linear-gradient(top, #eeccff 0%, #ffccaf 99%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeccff), color-stop(99%,#ffccaf)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #eeccff 0%,#ffccaf 99%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #eeccff 0%,#ffccaf 99%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #eeccff 0%,#ffccaf 99%); /* IE10+ */
background: linear-gradient(to bottom, #eeccff 0%,#ffccaf 99%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeccff', endColorstr='#ffccaf',GradientType=0 ); /* IE6-9 */
}
.cDewH {
background: #ffccaf; /* Old browsers */
background: -moz-linear-gradient(top, #ffccaf 1%, #eeccff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#ffccaf), color-stop(100%,#eeccff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffccaf 1%,#eeccff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffccaf 1%,#eeccff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffccaf 1%,#eeccff 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffccaf 1%,#eeccff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffccaf', endColorstr='#eeccff',GradientType=0 ); /* IE6-9 */
}
.cTempH, .cTempL, .cWind, .cPress, .cHum, .cSolar, .cRainH, .cRainL, .cDewL, .cDewH {
width: 20%;
min-width: 135px;
}
.recent {
color: blue;
}
</style>
</head>
<body>
<?php
// Connect to the database
$mysqli = mysqli($kerrentw_topten, $kerrentw_topten, $temporary, $kerrentw_topten);
if ($mysqli->connect_errno) {
die('Failed to connect to the database server - ' . $mysqli->connect_error);
}
// $dataArrays holds the query data, and the returned values
// initially only populate it with simple high/low type queries
$dataArrays =
array( // 0-displayOrder, 1-fieldName, 2-caption, 3-highVals?, 4-decimalPlaces, 5-CSSclass, 6-(returned values - append post SQL queries)
array(0,"Temperature Records ($unitT)",'cTempL'),
array(1,'MinTemp','Min Temp',false,1,'cTempL'),
array(2,'AvgTemp','Min Avg Temp',false,1,'cTempL'),
array(3,'MaxTemp','Lowest Max Temp',false,1,'cTempL'),
array(4,'MaxTemp - MinTemp','Smallest Daily Temp Range',false,1,'cTempL'),
array(5,'HeatDegDays','Max Heating Deg Days',true,1,'cTempL'),
array(6,'MaxTemp','Max Temp',true,1,'cTempH'),
array(7,'AvgTemp','Max Avg Temp',true,1,'cTempH'),
array(8,'MinTemp','Highest Min Temp',true,1,'cTempH'),
array(9,'MaxTemp - MinTemp', 'Greatest Daily Temp Range', true, 1, 'cTempH'),
array(10,'CoolDegDays','Max Cooling Deg Days',true,1,'cTempH'),
array(100,"Derived Temperature Records ($unitT)",'cDewH'),
array(101,'LowAppTemp','Min Apparent Temp',false,1,'cDewL'),
array(102,'HighAppTemp','Max Apparent Temp',true,1,'cDewH'),
array(103,'LowDewPoint','Min Dew Point',false,1,'cDewL'),
array(104,'HighDewPoint','Max Dew Point',true,1,'cDewH'),
array(105,'LowWindChill','Min Wind Chill',false,1,'cDewL'),
array(200,'Humidity Records (RH%)','cHumL'),
array(201,'LowHum','Min Humidity',false,0,'cHumL'),
array(202,'HighHum - LowHum', 'Greatest Daily Humidity Range', true, 1, 'cHumH'),
array(203,'HighHum - LowHum', 'Smallest Daily Humidity Range', false, 1, 'cHumL'),
array(300,"Wind Records ($unitW)",'cWind'),
array(301,'HighAvgWSpeed','Max Avg Wind Spd',true,0,'cWindH'),
//array(302,'HighAvgWSpeed','Lowest Max Avg Wind',false,0,'cWindL'),
array(303,'HighWindGust','Max Wind Gust Spd',true,0,'cWindH'),
array(304,'HighWindGust','Lowest Max Wind Gust',false,0,'cWindL'),
array(305,'TotWindRun',"Max Daily Wind Run ($unitWR)",true,1,'cWindH'),
array(306,'TotWindRun',"Min Daily Wind Run ($unitWR)",false,1,'cWindL'),
array(400,"Pressure Records ($unitP)",'cPress'),
array(401,'MinPress','Min Pressure',false,1,'cPressL'),
array(402,'MaxPress','Max Pressure',true,1,'cPressH'),
array(403,'MaxPress - MinPress','Smallest Daily Press Change',false,1,'cPressL'),
array(404,'MaxPress - MinPress','Greatest Daily Press Change',true,1,'cPressH'),
array(500,"Rain Records ($unitR)",'cRainH'),
array(501,'MaxRainRate',"Max Rain Rate ($unitRR)",true,1,'cRainH'),
array(502,'HighHourRain','Max Rain in 1hr',true,1,'cRainH'),
array(503,'TotRainFall','Max Daily rain',true,1,'cRainH'),
array(600,'Solar Records (since 21 April 2013)','cSolarH'),
array(601,'HighUV','Max UV Index',true,1,'cSolarH'),
array(602,'HoursSun','Max Sunshine hours',true,1,'cSolarH'),
// array(603,'CAST(HighSolarRad AS UNSIGNED)','Max Solar Radiation Wm⁻²',true,0,'cSolarH'), // need to fix dayfile table, using varchar!
array(603,'HighSolarRad','Max Solar Radiation Wm⁻²',true,0,'cSolarH'), // table fixed!
array(605,'TotalEvap',"Max Evapotranspiration ($unitR)",true,1,'cSolarH')
);
// start of SQL execution timer
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$startSQLtime = $mtime;
// Step though $dataArray and fetch the simple high/low data from MySQL
$len = count($dataArrays);
for ($x = 0; $x < $len; $x++) {
// do not process the 100's entry's, they are headers!
if ($dataArrays[$x][0] % 100 > 0) {
$vals = simpleHiLo($dataArrays[$x][1], $dataArrays[$x][3], $dataArrays[$x][4], $recentHighlight);
// store returned values in the array
$dataArrays[$x][6] = $vals;
}
}
//#### Now we add the 'non-standard' query data #####
//Driest months
$vals = wetDryMonthsYears(true, 1, true);
$dataArrays[] = array(504,'DryMonths', 'Driest Months', false, 1, 'cRainL', $vals);
//Wettest months
$vals = wetDryMonthsYears(false, 1, true);
$dataArrays[] = array(505,'WetMonths', 'Wettest Months', false, 1, 'cRainH', $vals);
//Driest years
//$vals = wetDryMonthsYears(true, ($unitR === 'mm' ? 0 : 1), false);
//$dataArrays[] = array(506,'WetYears', 'Driest Years', false, 1, 'cRainL', $vals);
//Wettest years
$vals = wetDryMonthsYears(false, ($unitR === 'mm' ? 0 : 1), false);
$dataArrays[] = array(507,'WetYears', 'Wettest Years', false, 1, 'cRainH', $vals);
//Longest runs of dry days
$vals = consecutiveDryWetDays('D', $recentHighlight);
$dataArrays[] = array(508,'DryDays', 'Consecutive Dry Days (end date)', false, 1, 'cRainL', $vals);
//Longest runs of wet days
$vals = consecutiveDryWetDays('W', $recentHighlight);
$dataArrays[] = array(509,'WetDays', 'Consecutive Wet Days (end date)', false, 1, 'cRainH', $vals);
//Most dry days in a month
$vals = rainDaysMonth(true);
$dataArrays[] = array(510,'DryCount', 'Most Dry Days in a Month', false, 0, 'cRainL', $vals);
//Most rain days in a month
$vals = rainDaysMonth(false);
$dataArrays[] = array(511,'WetCount', 'Most Rain Days in a Month', false, 0, 'cRainH', $vals);
//Dullest days
$vals = minMaxSolarRad($recentHighlight);
$dataArrays[] = array(604,'LowSolarRad','Lowest Max Solar Radiation Wm⁻²',true, 0, 'cSolarL', $vals);
//Frost days
$vals = minMaxFrostDays(true);
$dataArrays[] = array(11,'MinFrost','First Frost Day',false,0,'cTempL',$vals);
$vals = minMaxFrostDays(false);
$dataArrays[] = array(12,'MaxFrost','Last Frost Day',true,0,'cTempH',$vals);
$vals = cntFrostDays(false);
$dataArrays[] = array(13,'HiFrostCnt','Most Frost Days',true,0,'cTempL',$vals);
$vals = cntFrostDays(true);
$dataArrays[] = array(14,'LoFrostCnt','Least Frost Days',false,0,'cTempH',$vals);
//End of SQL execution timer
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totalSQLtime = ($endtime - $startSQLtime);
//sort the array for display
function cmp_by_firstSubElement($a, $b) {
return $a[0] - $b[0];
}
usort($dataArrays, "cmp_by_firstSubElement");
//### All done, end of the data queries
//###########################################################################################
// Some standard functions to perform the MySQL queries
// Get the 10 highest/lowest values for the supplied field
function simpleHiLo($fld, $hi, $dec, $rcnt) {
global $dayFileTableName, $mysqli;
$query = 'SELECT LogDate, ' .
"ROUND($fld, $dec), " .
"Logdate >= DATE_SUB(CURDATE(), INTERVAL $rcnt DAY) " .
"FROM $dayFileTableName " .
"WHERE $fld IS NOT NULL " .
"ORDER BY $fld " . ($hi ? 'DESC' : 'ASC') . ', LogDate ASC ' .
'LIMIT 10';
$result = $mysqli->query($query);
if (!$result) {
die('ERROR - Bad Select Statement (1) - ' . $mysqli->error);
}
// import the rows and put the data into an array
while ($row = $result->fetch_array()) {
$rtn[] = $row;
}
return $rtn;
}
// Get the 10 longest dry/wet spells, $dryWet = "D" or "W"
function consecutiveDryWetDays($dryWet, $rcnt) {
global $dayFileTableName, $rainDayThreshold, $mysqli;
$query = 'SELECT ' .
//'MIN(LogDate) AS date_from, ' .
'MAX(LogDate) AS date_to,' .
'COUNT(*) AS cnt, ' .
"MAX(Logdate) >= DATE_SUB(CURDATE(), INTERVAL $rcnt DAY) " .
'FROM ( ' .
'SELECT ' .
"@r := @r + (@rain != (TotRainFall >= $rainDayThreshold) OR @rain IS NULL) AS gr," .
"@rain := (TotRainFall >= $rainDayThreshold)," .
"IF (TotRainFall < $rainDayThreshold, 'D', 'W') AS wd," .
'df.LogDate ' .
'FROM (' .
'SELECT @r := 0,' .
'@rain := NULL' .
') vars,' .
"$dayFileTableName df ".
'ORDER BY LogDate' .
') x '.
"WHERE wd = '$dryWet' " .
'GROUP BY gr ' .
'ORDER BY cnt DESC, LogDate ASC ' .
'LIMIT 10';
$result = $mysqli->query($query);
if (!$result) {
die('ERROR - Bad Select Statement (2) - ' . $mysqli->error);
}
// import the rows and put the data into an array
while ($row = $result->fetch_array()) {
$rtn[] = $row;
}
return $rtn;
}
// Get the 10 wettest/driest months
function wetDryMonthsYears($dry, $dec, $mnth) {
global $dayFileTableName, $mysqli;
$query = "SELECT DATE_FORMAT(LogDate,'" . ($mnth ? '%b ' : '') . "%Y') AS intv, " .
"ROUND(SUM(TotRainFall), $dec) AS rain, " .
"DATE_FORMAT(LogDate,'" . ($mnth ? '%b ' : '') . "%Y') = DATE_FORMAT(CURDATE(),'" . ($mnth ? '%b ' : '') . "%Y')" .
"FROM $dayFileTableName " .
'GROUP BY intv ' .
'ORDER BY rain ' . ($dry ? 'ASC' : 'DESC') . ', LogDate ASC ' .
'LIMIT 10';
$result = $mysqli->query($query);
if (!$result) {
die('ERROR - Bad Select Statement (3) -' . $mysqli->error);
}
// import the rows and put the data into arrays
while ($row = $result->fetch_array()) {
$rtn[] = $row;
}
return $rtn;
}
// Get the 10 months with most/least rain days
function rainDaysMonth($dry) {
global $dayFileTableName, $mysqli;
$query = 'SELECT DATE_FORMAT(LogDate, "%b %Y") as intv, ' .
'COUNT(*) as days, ' .
'DATE_FORMAT(LogDate, "%b %Y") = DATE_FORMAT(CURDATE(), "%b %Y") ' .
"FROM $dayFileTableName " .
'WHERE TotRainFall ' . ($dry ? '= ' : '> ') . '0 ' .
'GROUP BY intv ' .
'ORDER BY days DESC, LogDate ASC ' .
'LIMIT 10';
$result = $mysqli->query($query);
if (!$result) {
die('ERROR - Bad Select Statement (4) -' . $mysqli->error);
}
// import the rows and put the data into arrays
while ($row = $result->fetch_array()) {
$rtn[] = $row;
}
return $rtn;
}
// Get the 10 dullest days
function minMaxSolarRad($rcnt) {
global $dayFileTableName, $mysqli;
$query = 'SELECT LogDate, ' .
'ROUND(HighSolarRad,0), ' .
"Logdate >= DATE_SUB(CURDATE(), INTERVAL $rcnt DAY) " .
"FROM $dayFileTableName " .
'WHERE HighSolarRad > 0 ' .
'ORDER BY HighSolarRad ASC, LogDate ASC ' .
'LIMIT 10';
$result = $mysqli->query($query);
if (!$result) {
die('ERROR - Bad Select Statement (5) -' . $mysqli->error);
}
// import the rows and put the data into arrays
while ($row = $result->fetch_array()) {
$rtn[] = $row;
}
return $rtn;
}
// Get the early/late Frost Days
function minMaxFrostDays($first) {
global $dayFileTableName, $mysqli;
$query = 'SELECT CONCAT(Y1,"/",RIGHT(CONCAT("0",Y1+1-2000),2)), '.
'DATE_FORMAT(D1, "%d %b"), '.
'Y1 = YEAR(CURDATE() - INTERVAL 7 MONTH) '.
'FROM ( '.
'SELECT '.
'YEAR(LogDate - INTERVAL 7 MONTH) AS Y1, '.
($first ? 'MIN(LogDate)' : 'MAX(logDate)').' AS D1 '.
"FROM $dayFileTableName D ".
'WHERE MinTemp <= 0 '.
// I don't have records for Winter 2009, they start 2010, so cannot
// determine the earliest frost for this period. Start @ period 2010/11
($first ? 'AND LogDate > "2010-07-01" ' : '').
'GROUP BY Y1 '.
') AS T '.
'ORDER BY DATE_FORMAT((D1 + INTERVAL 7 MONTH),"%m%d") '.($first ? 'ASC ' : 'DESC ').
'LIMIT 10';
$result = $mysqli->query($query);
if (!$result) {
die('ERROR - Bad Select Statement (6) -' . $mysqli->error);
}
// import the rows and put the data into arrays
while ($row = $result->fetch_array()) {
$rtn[] = $row;
}
return $rtn;
}
// Get the total Frost Days
function cntFrostDays($min) {
global $dayFileTableName, $mysqli;
$query = 'SELECT CONCAT(Y1,"/",RIGHT(CONCAT("0",Y1+1-2000),2)), '.
'D1, '.
'Y1 = YEAR(CURDATE() - INTERVAL 7 MONTH) '.
'FROM ( '.
'SELECT '.
'YEAR(LogDate - INTERVAL 7 MONTH) AS Y1, '.
'COUNT(*) AS D1 '.
"FROM $dayFileTableName D ".
'WHERE MinTemp <= 0 '.
'GROUP BY Y1 '.
') AS T '.
'ORDER BY D1 '.($min ? 'ASC ' : 'DESC ').
'LIMIT 10';
$result = $mysqli->query($query);
if (!$result) {
die('ERROR - Bad Select Statement (6) -' . $mysqli->error);
}
// import the rows and put the data into arrays
while ($row = $result->fetch_array()) {
$rtn[] = $row;
}
return $rtn;
}
// End of the server side script
//###########################################################################################
// Start to build the page for the client
?>
<!-- Header & Menu -->
<?php include 'content_header.php'; ?>
<div id="site_content">
<div class="container">
<!-- Banner -->
<?php include 'content_banner.php'; ?>
<!-- Content -->
<div class="row">
<div class="section -1u 10u">
<h1>Top 10 Records</h1>
<p class="not-mobile">This page shows some of the Top 10 highs and lows recorded by this weather station.
General records began on 13th January 2010, solar records on 21st April 2013.<br>
New records (within the last <?php echo ($recentHighlight-1) ?> days, current month, or current year) are highlighted in blue text.
The data is updated just after midnight each day.</p>
<table>
<tbody>
<?php
// Walk the data array X records at a time (5 sub-tables per row on the page)
$recs = count($dataArrays);
$currRec = 0; // current index into array
$currCell = 0; // current cell in row
while ($currRec < $recs) {
// is the current record a header?
if ($dataArrays[$currRec][0] % 100 === 0) {
// yes, so show a header row
if ($currCell > 0) {
// already in a data row, so pad it out with empty <td>s to fill the row
for ($x = $currCell; $x < $cells; $x++) {
// add any empty cells to pad the row
echo '<td> </td>';
}
// end the row
echo '</tr>';
}
// display the header
echo '<tr><td colspan=' . $cells . ' class="header ' . '">' . $dataArrays[$currRec][1] . '</td></tr>';
// start a new row
$currCell = 0;
} else {
// no it is a data record...
if ($currCell === 0) {
// first cell, so create a new row
echo '<tr>';
}
// create an embedded table to display it
echo '<td class="' . $dataArrays[$currRec][5] . '"><table class="dataTable"><caption>' . $dataArrays[$currRec][2] . '</caption><tbody>';
$num = count($dataArrays[$currRec][6]); // number of rows for this data table (may be less than 10)
for ($i = 0; $i < 10; $i++) {
// do we have any records left for this category?
if ($i < $num) {
// yep, so show them
//recent record?
$rcntClass = ($dataArrays[$currRec][6][$i][2] === '1' ? ' recent' : '');
echo ' <tr><td class="cell1' . $rcntClass . '">' . $dataArrays[$currRec][6][$i][1] . '</td><td class="cell2' . $rcntClass . '">' . $dataArrays[$currRec][6][$i][0] . '</td></tr>';
} else {
// nope, so display an empty pair of cells
echo ' <tr><td> </td><td> </td></tr>';
}
}
echo '</tbody></table></td>';
$currCell += 1;
if ($currCell === $cells) {
// we have filled a row
echo '</tr>';
// start a new one
$currCell = 0;
}
}
// next array record
$currRec += 1;
}
// Now just end the page structure
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php include 'content_footer.php'; ?>
</body>
</html>