Hey Guys,
I need a little help. I have a calendar script that I want to write a query for and pull out the day of the week, then have it send an email showing all the entries for that day. Unfortunately i'm querying a day, month, year as seperate fields and they are int not date fields. I have accomplished querying the database and used a date/mktime function to convert the int fields into a date field. Where I'm running into trouble is, I can't figure out how to pull this date field and compair it to todays date (date()), and have it display only the records from todays. Here is the code I have so far, I know it is very simple so If you have a better way of doing this, please let me know.
<?php
require("config.php");
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$query = "SELECT * FROM pec_mssgs ORDER BY m, d";
$result = mysql_query($query) or die('Nope, query didn\'t work');
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$d = $row['d'];
$m = $row['m'];
$y = $row['y'];
$title = $row['title'];
$text = $row['text'];
$newdate = date("Y-m-d", mktime(0, 0, 0, $m, $d, $y));
echo "$newdate ($text, $title)<br>\n";
}
if ($newdate == date("Y-m-d"))
{
echo "good if";
} else
echo "bad if";
?>
This displays:
2009-01-07 (test, test)
2009-05-19 (test, test)
2009-05-20 (this is a test, today is 20 may)
2009-05-25 (Have a Great Day!!, Memorial Day)
2009-05-25 (test, testing day)
bad if
So far it is doing what I want but I want only those listed above that match today's date. Then I can take those items and send them out in an e-mail.
Any help is much appreciated. Thx.