PHP Script uses custom CSS to generate HTML styled table to contain last nine database rows from the vehicle speed system.
- Converts MySQL DateTime entry
- YYYY/MM/DD H:i:s:xxx to h:i:s
- Converts Direction Integer to Text
- 1 = Up, 2=Down
$servername = “xxxxxxx”;
$username = “xxx”;
$password = “xxxxx”;
$dbname = “xxxxx”;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
$sql = “SELECT * FROM traffic ORDER BY Time DESC LIMIT 9”;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo “<table class=styled-table>”;
echo “<thead><tr><th>Time</th><th>Speed</th><th>Direction</th><th>Count</th><th>SD</th></tr></thead>”;
// output data of each row
echo “<tbody>”;
while($row = $result->fetch_assoc()) {
$secvar = “”;
{$secvar = strtotime((trim($row[“Time”])));}
{$secvar2 = date(“H:i:s”, $secvar);}
$firstvar = “”;
if (trim($row[‘Direction’]) ==1)
{$firstvar = “Up”;}
if (trim($row[‘Direction’]) ==2)
{$firstvar = “Down”;}
echo “<tr><td>”.$secvar2.”</td><td>”.$row[“Speed”].”</td><td>”.$firstvar.”</td><td>”.$row[“Count”].”</td><td>”.$row[“SD”].”</td></tr>”;
}
echo “</tbody>”;
echo “</table>”;
} else {
echo “0 results”;
}
$conn->close();