0% found this document useful (0 votes)
17 views2 pages

Index

This document displays sensor data from a database in a table, including the ID, date and time, sensor type, location, and recorded temperature, humidity, and pressure values. It connects to a MySQL database called "marisol_iot_db" and queries the "sensordata" table to retrieve the latest readings ordered by ID. The results are output in an HTML table with the sensor data fields.

Uploaded by

Marisol De Leon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Index

This document displays sensor data from a database in a table, including the ID, date and time, sensor type, location, and recorded temperature, humidity, and pressure values. It connects to a MySQL database called "marisol_iot_db" and queries the "sensordata" table to retrieve the latest readings ordered by ID. The results are output in an HTML table with the sensor data fields.

Uploaded by

Marisol De Leon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

<!

DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="5">
<link rel="stylesheet" type="text/css" href="style.css" media="screen"/>

<title> Sensor Data </title>

</head>

<body>

<h1>SENSOR DATA</h1>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "marisol_iot_db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, sensor, location, value1, value2, value3, reading_time FROM
sensordata ORDER BY id DESC"; /select items to display from

echo '<table cellspacing="5" ccellpadding="5">


<tr>
<th>ID</th>
<th>Data and Time</th>
<th>Sensor</th>
<th>Location</th>
<th>Temperature &deg</th>
<th>Humidity &#37;</th>
<th>Pressure</th>
<tr>';

if ($result = $conn->quary($sql)) {
while ($row = $result->fetch_assoc()) {
$row_id = $row["id"];
$row_reading_time = $row["reading_time"];
$row_sensor = $row["$sensor"];
$row_location = $row["location"];
$row_value1 = $row["value1"];
$row_value2 = $row["value2"];
$row_value3 = $row["value3"];

// Uncomment to set timezone to - 1 hour (you can change 1 to any


number)
// $row_reading_time = data("Y-m-d H:i:s", strtotime("$row_reading_time
- 1 hors"));

//uncomment to set timezone to + 4 hours (you can change 4 to any


number)
//$row_reading_time = data("Y-m-d H:i:s", strtotime("$row_reading_time
+ 4 hours"));
echo '<tr>
<td>' . $row_id . '</td>
<td>' . $row_reading_time . '</td>
<td>' . $row_sensor . '</td>
<td>' . $row_location . '</td>
<td>' . $row_value1 . '</td>
<td>' . $row_value2 . '</td>
<td>' . $row_value3 . '</td>

</tr>';
}
$result->free();
}

$conn->close();
?>
</table>

</body>
</html>

</body>
</html>

You might also like