bschultz Posted November 23, 2009 Share Posted November 23, 2009 I need to query a database and select a list of names whose birthday is next week. The dates are in the database in Y-M-D format (2009-11-23). Here's my code... $sql = "SELECT * FROM kids WHERE DATE_SUB(WEEKOFYEAR(),INTERVAL +1) = age"; $dbq = mysql_query($sql,$dbc); //now spit out the results while ($row = mysql_fetch_array($dbq)) { echo "".$row[name]." ".$row[address]." ".$row[address]." ".$row[city]." ".$row[state]." ".$row[phone]." ".$row[email]." ".$row[age]." <br />"; } echo "<br />"; ?> I'm getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 13 Line 13 is this line... while ($row = mysql_fetch_array($dbq)) { Any ideas where I'm messing up the query? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/182715-problem-with-select-and-dates-week-of-year/ Share on other sites More sharing options...
JustLikeIcarus Posted November 24, 2009 Share Posted November 24, 2009 I believe 'INTERVAL +7' is incorrect. Try this assuming your storing the date of birth in the age field this below should work for you. SELECT * FROM kids WHERE WEEK(age) = WEEK(DATE_ADD(NOW(), INTERVAL 7 DAY)) Quote Link to comment https://forums.phpfreaks.com/topic/182715-problem-with-select-and-dates-week-of-year/#findComment-964693 Share on other sites More sharing options...
bschultz Posted November 25, 2009 Author Share Posted November 25, 2009 That did it...thanks! Quote Link to comment https://forums.phpfreaks.com/topic/182715-problem-with-select-and-dates-week-of-year/#findComment-965132 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.