下表按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>";
答案 0 :(得分:0)
您也可以在mysql中进行分组,不需要在PHP中计算:
SELECT count(*), username, datesubmitted
FROM submission
GROUP BY username, month(datesubmitted)
现在你可以在显示表格中重复结果