I am trying to check for Birthdays from data in the table using CURDATE() function. Sadly My code currently only outputs names if the birthDate is the current date! (i.e inluding year). I am trying to figure out how to ignore Year here and only compare month and day.
Please assume this is the table
| book_no | name | dob | mobile_no |
|---------|-----------|------------|------------|
| 1 | ABCD | 1995-08-01 | 123456789 |
| 2 | EFGH | 2016-08-01 | 123456789 |
| 3 | HIKJ | 2016-05-01 | 123456789 |
| 4 | LMNO | 2016-08-01 | 123456789 |
| 5 | PQRS | 1995-08-01 | 123456789 |
This is the code
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "gold";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$sql1 = "SHOW TABLES";
$result1 = mysqli_query($conn,$sql1);
if(!$result1)
{
echo "Error fetching data from tempTable: " . mysqli_error($conn);
}
else
{
while ($row1 = $result1->fetch_assoc())
{
foreach($row1 as $key1 => $var1)
{
$sql2 = "SELECT name,mobile_no FROM " .$var1. " WHERE dob = CURDATE()";
$result2 = mysqli_query($conn,$sql2);
$bBoy = array();
if(!$result2)
{
echo "Error fetching data from tempTable: " . mysqli_error($conn);
}
else
{
while ($row2 = $result2->fetch_assoc())
{
echo $row2['name']."<br>";
echo $row2['mobile_no']."<br>";
}
}
}
}
}
>?
This code only outputs
EFGH
123456789
LMNO
123456789
while it should have been all except book_no -3. Please Help