我有一張用戶表,我需要運行報表並顯示給定年份中每個月用戶進入系統的次數。我創建了第一列返回不同用戶的表格。接下來,在右側,我想顯示用戶每個月輸入了多少次。我目前的代碼只計算每個月的總計,並將所有用戶的每月總計。在下面的例子中,每個用戶列出5月7日,6月13日和7月12日。但我希望它能像下面那樣展示它按月分解的位置。不同記錄計數總計按月計
Users May June July
User1 1 2 3
User2 1 1 2
User3 5 10 7
<?php
$sql = "SELECT record,count(*) as TotalCount,
(select DISTINCT count(*) from Table1 WHERE datereceived BETWEEN '2012-05-01' AND '2012-05-31') as May,
(select DISTINCT count(*) from Table1 WHERE datereceived BETWEEN '2012-06-01' AND '2012-06-30') as June,
(select DISTINCT count(*) from Table1 WHERE datereceived BETWEEN '2012-07-01' AND '2012-07-31') as July
FROM Table1 GROUP BY record";
$params = array();
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$stmt = sqlsrv_query($conn, $sql , $params, $options);
if($stmt === false)
{
echo "Error in query preparation/execution.\n";
die(print_r(sqlsrv_errors(), true));
}
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
?>
<tr id="styling">
<td class="style"><?php echo $row['record']; ?></td>
<td class="style"><?php echo $row['May']; ?></td>
<td class="style"><?php echo $row['June']; ?></td>
<td class="style"><?php echo $row['July']; ?></td>
</tr>
<?php } ?>
你能告訴你的表結構體? – 2012-07-31 21:16:19