MySQL

Select rows for the current day and month

What does this script do?

This PHP script connects to a MySQL database and retrieves historical events that occurred on today's date (same day and month) from a table called today_in_history.

Demo
YearEvent
1642 Christiaan Huygens discovers the Martian south polar cap
1704 English defeat French at Battle of Blenheim
1831 Nat Turner leads uprising of slaves in Virginia
1847 English astronomer J.R. Hind discovers asteroid Iris
1876 Reciprocity Treaty between US & Hawaii ratified
1932 Yankee pitcher Red Ruffing homers & wins the game 1-0 in 10 tying the feat of Senator Tom Hughes who also won 1-0 in 10 in 1906
1939 Yankees set AL shutout margin with 21-0 victory over the A's
1960 Central African Republic proclaims independence from France
1961 Berlin Wall erected in East Germany
3114 BC The Mayan "long count" calendar system begins
MySQL Query
SELECT * FROM today_in_history WHERE DAY(mcm_date)=DAY(NOW()) AND MONTH(mcm_date)=MONTH(NOW()) LIMIT 0, 60
PHP
$conn = new mysqli ("server", "user", "password", "database");
mysqli_set_charset ($conn, "utf8");

if ($conn -> connect_error) {
die ("Error: " . $conn->connect_error);
} 

$sql = "SELECT * FROM today_in_history WHERE DAY(mcm_date)=DAY(NOW()) AND MONTH(mcm_date)=MONTH(NOW()) LIMIT 0, 60";
$result = $conn -> query($sql);

echo "<table id='demoTable' class='table table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Year</th>";
echo "<th>Event</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>"; 

while ($row = $result -> fetch_assoc()) { 

$var_year = date_create($row["mcm_date"]);

echo "<tr>";
echo '<td>' . date_format($var_year, 'Y') . '</td>' . "\n";
echo "<td>" . $row["mcm_event"] . "</td>";
echo "</tr>";
}

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