开发者

Summarize php result

开发者 https://www.devze.com 2023-02-14 09:24 出处:网络
So far i got this code: func开发者_如何转开发tion toplist() {$sql = \"SELECT * FROM list WHERE date=curdate()\";

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 points

Now I would like it to summarize like this (from the example above):

User two 450 points

User one 300 points

And 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
0

精彩评论

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