【发布时间】:2015-02-20 10:02:06
【问题描述】:
我的 SQL 查询是选择日期并进行计数,以及按日期分组。
我不知道如何逐行输出JSON输出。
$sql = "SELECT DATE(timestamp), COUNT(eventid)
FROM `tablex`
WHERE timestamp >= date_sub(CURRENT_DATE, interval 30 day)
GROUP BY DATE(timestamp) ";
$stream = mysqli_query($conn, $sql);
if (mysqli_num_rows($stream) > 0) {
while($row = mysqli_fetch_assoc($stream)) {
// Is this where I should echo JSON?
// The problem is I'm not retrieving records but count and doing
// a grouping
}}
【问题讨论】:
-
你能把你想要的格式显示为o/p吗?
-
输出格式应该是:[{ "timestamp": "2015-02-20", "count": 417 }]
标签: php mysql json count grouping