Jump to content

Problem with select and dates / week of year


Recommended Posts

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]."&nbsp<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.

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))

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.