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
1842 US Naval Observatory is authorized by an act of Congress
1850 California Pioneers organized at Montgomery & Clay Streets
1886 1st major earthquake recorded in eastern US at Charleston S.C
1886 Crocker-Woolworth National Bank organized
1950 Gil Hodges hits 4 homers in 1 game
1955 1st sun-powered automobile demonstrated Chicago Il
1955 1st microwave television station operated - Lufkin Texas
1957 Malaysia gains independence from Britain (National Day)
1962 Trinidad & Tobago gains independence from Britain (National Day)
1963 Malaysia Day
1977 Aleksandr Fedotov sets world aircraft altitude record of 38.26 km (125 524 ft) in a Mikoyan E-266M turbojet
1980 Poland's Solidarity labor union founded
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();
?>