我试图在过去 7 天内获得注册用户,所以我有 users 表
+-----+------------+--------------+
| ID | USERNAME | ADDED |
+-----+------------+--------------+
| 1 | Vlad | 1347386878 |
+-----+------------+--------------+
| 2 | Test | 1347386578 |
+-----+------------+--------------+
我在sql下面试过,但输出是空的,没有错误......我需要一些从今天到7天前的东西
SELECT date(added), COUNT(id) AS num_registered
FROM users
WHERE added < CURDATE()
AND added > CURDATE() - INTERVAL 7 DAYS
GROUP BY date(added) LIMIT 1, 7
任何建议如何做到这一点?
编辑:
$mysql_query = mysql_query('SELECT added, DATE(added), COUNT(id) AS num_reg FROM users_test WHERE added < (UNIX_TIMESTAMP() - (7 * 24 * 60 * 60)) GROUP BY DATE(added) LIMIT 1, 7') or die(mysql_error());
while($row = mysql_fetch_array($mysql_query))
{
$month = date('F', $row['added']);
$day = date('j', $row['added']);
$textbuilder .= '
<li>
<a href="#" title="'.$month.' '.$day.', '.$row['num_reg'].' registered">
<span class="label">'.$day.'</span>
<span class="count" style="height: 20%">('.$row['num_reg'].')</span>
</a>
</li>';
}
桌子:
CREATE TABLE IF NOT EXISTS `users_test` (
`id` int(10) NOT NULL,
`username` varchar(60) NOT NULL,
`added` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `users_test` (`id`, `username`, `added`) VALUES
(1, 'Test', 1347303641),
(2, 'Test1', 1347217241),
(3, 'Test2', 1347130841),
(4, 'Test3', 1347044441);