How can PHP be used to display a green or red light based on certain conditions in a MySQL database?

To display a green or red light based on certain conditions in a MySQL database using PHP, you can query the database to check the conditions and then dynamically generate HTML code to display the corresponding colored light. For example, you can use an IF statement to check a specific column value in the database and then echo out HTML code for a green or red light accordingly.

<?php
// Connect to MySQL database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query database to check conditions
$query = "SELECT status FROM table WHERE condition = 'value'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);

// Display green or red light based on condition
if ($row['status'] == 'green') {
    echo '<div style="width: 20px; height: 20px; background-color: green;"></div>';
} else {
    echo '<div style="width: 20px; height: 20px; background-color: red;"></div>';
}

// Close database connection
mysqli_close($connection);
?>