开发者

why isn't this pulling data from 7 days back?

I can't seem to figure out where I'm going wrong here. This is what I have:

$query = ("SELECT * FROM contacts WHERE agentassigned = 'agent' AND reminder ='$reminder date开发者_运维技巧("Y-m-d",strtotime("+7 day"))' ORDER BY firstname") or die ('Error: ' .mysql_error());


MySQL will not execute the PHP code you sent it in the query.

That's probably not what you meant to do. Instead, concatenate the result of the date() call.

$query = "SELECT * FROM contacts WHERE agentassigned = 'agent' AND reminder ='$reminder " . date("Y-m-d",strtotime("+7 day")) . "' ORDER BY firstname";

Based on your comments, you actually want something like this:

SELECT 
  *
FROM
  contacts
WHERE
  agentassigned = 'agent'
AND
  reminder_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL 7 DAY

Where you need to add a column reminder_date to your table which contains the date of the reminder. You don't want to try to parse it out of a string like you're doing. It's slow and wrong.


You cannot interpolate a function call inside a double quoted string. Instead do the function call first and save the result into $date:

$date = date("Y-m-d",strtotime("+7 day"));
$query = ("SELECT * FROM contacts WHERE agentassigned = 'agent' AND reminder ='$reminder $date' ORDER BY firstname") or die ('Error:  ' .mysql_error());


Because your query seems to look 7 days into future. Try "-7 day" instead of "+7 day".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜