sql 结果,如何计算 php 代码中每个名称重复名称的分数

sql results, How to count points for duplicate names for each name in php code

我在这个网站上有 sql table

Nourena

注意:我想编辑此 php 代码

<?php 

// make connecion
mysql_connect('host', 'host user', '');

// Select Database
mysql_select_db ('database name');

$sql="SELECT * FROM database_name";

$records=mysql_query($sql);



?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>الاحصائيات النهائية لمسابقة اكتوبر</title>
</head>

<body>

<table>
    
   <tr>
    <th style="width: 40px;">Pos.</th>
    <th style="">Name</th>
    <th style="width: 60px;">Points</th>
   <tr>
<?php 

 while($database_name=mysql_fetch_assoc($records)) {
  
  echo "<tr>"; 
  
  echo "<td>".$database_name[toplist_id]."</td>"; 
  
  echo "<td>".$database_name[name]."</td>";
  
  echo "<td>".$database_name[points]."</td>";
  
  echo "</tr>"; 
  
  
  }// End While

?>               
           
                  
 </table>

</body>
</html>

<?php 

?>

如您在 table 中看到的,我有重复的名字,例如 beltagy 和这个名字的积分。

我想为每个名字计算点数并显示不重复的名字。

也想把像“.pos”这样的名字排在table根据每个名字最多就收到多少分

现在我想这样显示 table

.pos    name      points

  1     beltagy     9
  2     test        8

我是新手,很快就需要这个,很抱歉英语不好

将您的查询更改为:

$sql="SELECT toplist_id, name, SUM(points) as totalPoints
      FROM database_name
      GROUP BY name
      ORDER BY SUM(points) as totalPoint DESC";

** 'database_name' 实际上应该是 table 名称,但您在原始问题中使用了 'database_name'。