Language: PHP and MySQL
What I'm trying to do:
Email users who are celebrating their birthdays within the week, a week ahead from their birthday.
Facts:
birthday
dates are stored in the standard YYYY-MM-DD date format
Technically:
- Retrieve
'birthday'
(YYYY-MM-DD) from the database, and select users whose'birthday'
is within the current week (regardless of the year). - Output results.
What I'm doing:
Assuming that we already have a database connection...
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM table_birthdays WHERE strftime('%W', column_birthday) == strftime('%W', 'now')");
// debug
var_dump($result);
//fetch the data from the database
while ($row = mysql_fetch_array($result)) {
// DO SOMETHING WITH RESULTS
echo $row['column_birthday']."<br><br>" .
"Email: " . $row['column_email'];
}
//close the connection
mysql_close($dbhandle);
Based on the above code...
I am currently getting the following results:
var_dump()
returns:bool(false)
And the while loop returns:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...
Question:
Am I doing it right? Will the while loop not return boolean
if results are found?
Or... should I be querying this differently in order to achieve my desired outcome? (quoted below)
Desired outcome:
Email users who are celebrating their birthdays within the week, a week ahead from their birthday.