I am racking my brain as to how this might work. I have tried a number of variations and can not seem to get accurate results.
I need to check my cdate field which holds the the date and time stamp. Then i need to check for new projects less than 7days and display the row count, then for projects between 7 and 14days and display the row count and finally for projects over 14days old and display the row count.
What i have is a dashboard that shows a number count for those ( NEW / 7+ days / 14+ days )
This is my table field:
cdate
2011-07-29 19:21:29
2011-08-05 19:25:14
2011-08-05 19:25:23
2011-03-29 19:21:29
2011-08-05 19:25:23
2011-08-05 19:25:23
And this is my current queries:
$quotesNEW_sql = mysql_query("SELECT * FROM projects WHERE status=0 AND cdate >= NOW() AND cdate <= NOW() + INTERVAL 6 DAY") or die(mysql_error());
$quotes_result_new = mysql_num_rows($quotesNEW_sql);
$quotesSEVEN_sql = mysql_query("SELECT * FROM projects WHERE status=0 AND开发者_开发知识库 cdate >= NOW() AND cdate <= NOW() + INTERVAL 7 DAY") or die(mysql_error());
$quotes_result_seven = mysql_num_rows($quotesSEVEN_sql);
$quotesFOURTEEN_sql = mysql_query("SELECT * FROM projects WHERE status=0 AND cdate >= NOW() AND cdate <= NOW() + INTERVAL 15 DAY") or die(mysql_error());
$quotes_result_fourteen = mysql_num_rows($quotesFOURTEEN_sql);
Thanks in advance :) John
If all you need is the count, you could use GROUP BY
to do it with a single query.
SELECT COUNT(crate), FLOOR(ABS(DATEDIFF(cdate, NOW()) / 7)) AS day_interval
FROM projects
WHERE status = 0
GROUP BY day_interval;
day_interval
is broken down as follows:
- 0 = New
- 1 = 7-13 days
- 2 = 14+ days
精彩评论