制作HTML表列出变量的月度快照

时间:2011-08-18 05:26:05

标签: php mysql

下表按username降序列出total。如何在每个行列表中列出第一列中列出的total$date最高的人?

$query = "SELECT username, datesubmitted, COUNT(1) AS total 
    FROM submission 
    GROUP BY username

ORDER BY total DESC"

$result = mysql_query($query);

$date = strtotime("January 1, 2010");

$arr = array();

echo "<table>";
    while ($row = mysql_fetch_array($result)) { 

    $date = strtotime("+1 month", $date);

            echo '<tr>';
            echo '<td >'.date("F j, Y", $date).'</td>';
            echo '<td >'.stripslashes($row["username"]).'</a></td>';
            echo '<td >'.number_format(($row["total"])).'</td>';
            echo '</tr>'; 
}

echo "</table>";

1 个答案:

答案 0 :(得分:0)

您也可以在mysql中进行分组,不需要在PHP中计算:

SELECT count(*), username, datesubmitted
    FROM submission 
    GROUP BY username, month(datesubmitted)

现在你可以在显示表格中重复结果