我试图显示玩家得分的统计数据,但是有时同一个玩家被添加到具有相同玩家ID的数据库中,当玩家被添加两次时,我如何将这些值一起添加以显示为总数,而不是回声玩家两次.
db结构示例:
playerID | Goals | Season | leagueID
1 5 1 1
2 1 1 1
1 2 1 2
5 3 1 1
1 3 2 2
2 2 2 1
PHP:
$query = $db->query('SELECT * FROM playerstats ORDER BY goals DESC LIMIT 30');
$num = $query->num_rows;
if($num > 0) {
foreach($query as $row) {
$playerID = $row['playerID'];
$goals = $row['goals'];
echo '
'.$playerID.''.$goals.'';
}
}
这将显示玩家ID 1,3分开的时间.
我怎样才能让所有目标加在一起只显示一次playerID 1(10)
我已经尝试将查询更改为:SELECT DISTINCT * FROM playerstats ORDER BY目标DESC LIMIT 30但这没有任何区别.