这是一个非常基本的MySQL,但我还没有弄清楚如何正确地完成它。。
示例:我有一个名为"table1"的DB表,其中包含用户访问者数据的记录列表。列:"ID"、"TM"answers"IP"
"TM"包含存储记录的时间戳。
我有一个PHP代码,我在其中循环从开始日期到当前日期的日子。像这个例子:
// Start date
$startdateforarray = '2010-07-21';
// End date
$end_date = date("Y-m-d");
while (strtotime($startdateforarray) <= strtotime($end_date)) {
$timestamp = strtotime($startdateforarray);
//Here I want to run my MySQL Query...
$startdateforarray = date ("Y-m-d", strtotime("+1 day", strtotime($startdateforarray)));
}
现在,在循环中,我想进行一个查询,统计"table1"中每天有多少结果。
因此MySQL查询应该类似于:
"SELECT * FROM table1 WHERE TM = (day of $timestamp)"
当然($timestamp的日期)是我有问题的地方。我知道这应该很简单,但我还没有找到解决方案。。
假设时间戳是指Unix时间戳,则可以执行
SELECT * FROM table1 WHERE FROM_UNIXTIME(TM,'%Y-%m-%d') = '2010-07-21'