Weather Diary: Difference between revisions

1,626 bytes added ,  18:12, 31 May 2020
m
Line 39: Line 39:


== How to edit the MX Weather Diary ==
== How to edit the MX Weather Diary ==
=== Using the admin interface ===


#Under the '''Edit''' tab, select '''Weather Diary''' and a calendar based selector appears.
#Under the '''Edit''' tab, select '''Weather Diary''' and a calendar based selector appears.
#Click on required date, enter any Comment, tick the boxes for falling, and lying.
#Click on required date, enter any Comment (stored as "Entry" in the database), tick the boxes for falling, and lying.
#Use the spin selector or type in a snow depth. This field takes decimals (it is labelled as "cm", although you could select a different unit and ignore units shown!).
#Use the spin selector or type in a snow depth. This field takes decimals (it is labelled as "cm", although you could select a different unit and ignore units shown!).
=== Accessing outside MX ===
The weather diary is stored in [[diary.db|a sqLite database]] and that can be easily accessed by any ODBC software e.g. Libre Office. It can also be accessed using PDO instructions in PHP Hypertext Preprocessor.
Here is an example in a PHP 7.3 (there are changes for PHP 7.4) script of accessing any one day ($rowMetDayStamp in yyyy-mm-dd format):
<pre>$diary = 'sqlite:' . $snowDiary; // Parameter to identify a SQLite database puts a prefix in front of file path
$dbhandle = new PDO($diary);  // connect to db
if($dbhandle === false)
{
$liteError = sqlite_last_error ($dbhandle );
echo ' Error: ' . sqlite_error_string ($liteError);
}else{
if($debug) echo $lf . '============================' . $lf . 'Success, database ' . $diary . ' is open' . $lf;
$queryRead =  "SELECT ALL *  FROM " . "'DiaryData'";
$statement = $dbhandle -> query($queryRead);
if($statement === false)
{
$liteError = sqlite_last_error ($dbhandle );
echo ' Error: ' . sqlite_error_string ($liteError);
}else{
$jump = false;
foreach ($statement as $row)
{
foreach($row as $key => $value )
{
if($key == 'Timestamp')
{
$keyDate = substr($value, 0, 10);
}
if($keyDate != $rowMetDayStamp) break;
if($key == 'snowFalling') $falling = $value;
if($key == 'snowLying') $lying = $value;
if($key == 'snowDepth') $depth = $value;
if($key == 'entry') $Entry = $value;
$jump = true;
        }
        if($jump)
{
$snowKnown = true;
goto snowDone;
}
}
}
}
</pre>


== Web tags available for your web site ==
== Web tags available for your web site ==
5,838

edits