The table below lists username
by total
descending. How can I make each row list whoever had the highest total
on th开发者_Go百科e $date
listed in the first column?
$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>";
You can get the grouping in mysql as well, no need count in PHP:
SELECT count(*), username, datesubmitted
FROM submission
GROUP BY username, month(datesubmitted)
Now you can just iterate over the result in display the table
精彩评论