So far i got this code:
func开发者_如何转开发tion toplist() {$sql = "SELECT * FROM list WHERE date=curdate()";
$result = mysql_query($sql);
$num= mysql_numrows($result);
if ( mysql_num_rows($result) ) {
$i=0;
while( $i < $num) {
$user = mysql_real_escape_string(mysql_result($result, $i, "user"));
$todayscore = mysql_real_escape_string(mysql_result($result, $i, "todayscore"));
echo '
'.mysql_real_escape_string(mysql_result($result, $i, "user")).'
'.mysql_real_escape_string(mysql_result($result, $i, "todayscore ")).' points
<br/>';
$i++;
}
}}
This results in a list like this:
User two 200 points User one 300 points User two 150 points User two 100 pointsNow I would like it to summarize like this (from the example above):
User two 450 points User one 300 pointsAnd if possible, arange so that the user with the most points gets on top the others.
Thanks in advance.
SELECT SUM(todayscore) AS points, user FROM list WHERE date = curdate() GROUP BY user ORDER BY points DESC
精彩评论