开发者

Making an HTML table list monthly snapshots of a variable

开发者 https://www.devze.com 2023-03-29 02:02 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消