为什么不从7天前提取数据? [英] why isn't this pulling data from 7 days back?

查看:47
本文介绍了为什么不从7天前提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚我要去哪里.这就是我所拥有的:

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将不会执行您在查询中发送的PHP代码.

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

这可能不是您的本意.而是连接date()调用的结果.

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

需要在表中添加列reminder_date的位置,其中包含提醒的日期.您不想像您所做的那样尝试从字符串中解析出它.这很慢而且是错误的.

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.

这篇关于为什么不从7天前提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆