From bfddcd42e2c24dca8cfb59631047579d0b0eb513 Mon Sep 17 00:00:00 2001 From: Jonny Ervine Date: Wed, 3 Jun 2015 11:26:58 +0800 Subject: [PATCH] Create getData.php The PHP file that will retrieve the data from the database. Currently hardcoded to the last 360 entries. This will be altered at some point. --- getData.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 getData.php diff --git a/getData.php b/getData.php new file mode 100644 index 0000000..92beb51 --- /dev/null +++ b/getData.php @@ -0,0 +1,45 @@ + 'Date and Time', 'type' => 'number'), + array('label' => 'Temperature', 'type' => 'number'), + array('label' => 'Humidity', 'type' => 'number') +); + +// Create connection +//$conn = new mysqli($servername, $username, $password, $dbname); +$conn = mysqli_connect($servername, $username, $password, $dbname); +// Check connection +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +$sql = "SELECT ComputerTime, Temperature, Humidity from TempHumid ORDER BY id DESC LIMIT 360"; +$result = mysqli_query($conn,$sql); + +//if ($result->num_rows > 0) { + // output data of each row + while($row = mysqli_fetch_array($result)) { + $temp = array(); +// $datetime = date('d/m/Y H:i', $row[0]); +// $temp[] = array('v' => $datetime); + $temp[] = array('v' => $row[0]); + $temp[] = array('v' => $row[1]); + $temp[] = array('v' => $row[2]); + $rows[] = array('c' => $temp); + } +//} else { +// echo "No current temperature - ERROR?"; +//} +$table['rows'] = $rows; +header('Content-type: application/json'); +echo json_encode($table); +$conn->close(); +?>