Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

php - 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());
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...