您将需要汇总数据。试试这个查询:
SELECt DATE(data_timestamp), COUNT(visitor_id)FROM analytics_tableWHERe DATE(data_timestamp) BETWEEN '2011-05-01' AND '2011-05-31'GROUP BY 1
这是您填充月度数据的方式( 警告:未测试! ):
<?php$sql = "SELECt DATE(data_timestamp), COUNT(visitor_id)FROM analytics_tableWHERe DATE(data_timestamp) BETWEEN '2011-05-01' AND '2011-05-31'GROUP BY 1";$rs = mysql_query($rs);$date1 = $datex = '2011-05-01';$date2 = '2011-05-31';$arrayData = $tmpArray = array();while( $r = mysql_fetch_array($rs) ){ $tmpArray[$r['date']] = $r['count'];}while( $datex <= $date2){ if( isset($tmpArray[$datex]) ) { $arrayData[$datex] = $tmpArray[$datex]; } else { $arrayData[$datex] = 0; } list( $y, $m, $d) = explode('-', $datex); $datex = date('Y-m-d', mktime(0, 0, 0, $m, $d, $y));}?>
该查询使用:
- DATE()以从您的数据中获取日期,以及
- COUNT()用于计算该特定日期以来的总数据。
- 和GROUP BY可以根据您选择的字段对数据进行分组。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)