In what ways can MySQL be effectively utilized in a PHP project like a weekly calendar to assign activities to each calculated day?
To effectively utilize MySQL in a PHP project like a weekly calendar to assign activities to each calculated day, you can create a database table to store the activities with fields for the day, activity name, and any other relevant information. You can then use PHP to query the database to retrieve and display the activities for each day on the calendar.
// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "calendar_db");
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
// Query database to retrieve activities for each day
$query = "SELECT * FROM activities WHERE day = 'Monday'";
$result = $mysqli->query($query);
// Display activities for Monday
echo "<h2>Monday</h2>";
while($row = $result->fetch_assoc()) {
echo "<p>" . $row['activity_name'] . "</p>";
}
// Repeat the above steps for each day of the week
// Remember to close the database connection at the end
$mysqli->close();