php 在 table 中对列中的单元格进行排序,从 1 到无限

php sort cells in column from 1 to unlimited in table

我有 table 和 php 这样的代码

name    points

jeme      19
yoka      15
zinga     13

请用 php 代码完成,我不会给你我的代码来编辑

<?php 

// make connecion
mysql_connect('localhost', 'db user', '');

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


$sql="SELECT sum(points) as sumpoints , name FROM wp_wp_pro_quiz_toplist group by name order by sumpoints DESC";

$records=mysql_query($sql);




?>

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

<body>

<table class="wpProQuiz_toplistTable">
    
   <tr>
   
    <th style="">Name</th>
    <th style="width: 60px;">Points</th>
   <tr>
<?php 

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

?>               
           
                  
 </table>

</body>
</html>

这个 table 一切都很好,我按名字排序了谁赢得了更多的分数,如你所见,但我仍然想要另一个专栏,我将其称为 [position] 和 shourcut for it pos。 ,因为我想通过这种方式(数字 1-2-3-4)对用户进行排名

pos.     name      points

 1       jeme         19
 2       yoka         15
 3       zinga        13

您可以为 html 中的位置添加一列。 然后,当您解析已排序的数据时,您可以像这样递增一个变量:

$i=1;
while($wp_wp_pro_quiz_toplist=mysql_fetch_assoc($records)) {
         echo "<tr>";
         echo "<td>".$i++."</td>";
         echo "<td>".$wp_wp_pro_quiz_toplist[name]."</td>";
         echo "<td>".$wp_wp_pro_quiz_toplist[sumpoints]."</td>";
         echo "</tr>"; 
}// End While