i trying check birthdays data in table using curdate() function. sadly code outputs names if birthdate current date! (i.e inluding year). trying figure out how ignore year here , only compare month , day.
please assume 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 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 temptable: " . mysqli_error($conn); } else { while ($row1 = $result1->fetch_assoc()) { foreach($row1 $key1 => $var1) { $sql2 = "select name,mobile_no " .$var1. " dob = curdate()"; $result2 = mysqli_query($conn,$sql2); $bboy = array(); if(!$result2) { echo "error fetching data temptable: " . mysqli_error($conn); } else { while ($row2 = $result2->fetch_assoc()) { echo $row2['name']."<br>"; echo $row2['mobile_no']."<br>"; } } } } } >?
this code outputs
efgh 123456789 lmno 123456789
while should have been except book_no -3. please help
use month , day functions provided in mysql compare parts of date date have stored in table.
$sql2 = "select name,mobile_no " .$var1. " month(dob) = " . date('m') . " , day(dob) = " . date('d');
Comments
Post a Comment