现场时间有2013-09-02 07:54:28
这样的条目,我希望得到每天的金额。在伪文本中它会像这样工作:
如上所述的条目,我在数组中有一个数字:
$q1 = mysql_query("SELECT time FROM stats WHERE seite = '2'");
while ($row = mysql_fetch_array($q1, MYSQL_ASSOC)) {
$all[] = $row["time"];
}
print_r($all);
答案 0 :(得分:0)
如果你在循环中做其他逻辑:
$all = array();
$q1 = mysql_query("SELECT time, DATE(time) AS timeDate FROM stats WHERE seite = '2'");
while ($row = mysql_fetch_array($q1, MYSQL_ASSOC)) {
if (!isset($all[$row['timeDate']])) {
$all[$row['timeDate']] = 0;
}
$all[$row['timeDate']]++;
// other logic
}
print_r($all);
或者如果这是整个逻辑,只计算相同的日期:
$all = array();
$q1 = mysql_query("SELECT DATE(time) AS timeDate, COUNT(time) timeCount FROM stats WHERE seite = '2' GROUP BY DATE(time)");
while ($row = mysql_fetch_array($q1, MYSQL_ASSOC)) {
$all[$row['timeDate']] = $row['timeCount'];
}
print_r($all);
答案 1 :(得分:0)
您可以通过SQL查询找到金额而无需通过php处理。
SELECT DATE_FORMAT(time, '%Y-%m-%d') AS day, COUNT(*) AS amount FROM stats WHERE seite = '2' GROUP BY day;
答案 2 :(得分:0)
SELECT date(time), count(time) FROM stats WHERE seite = '2' group by date(time)