dongraobei6719 2015-08-20 13:38
浏览 73
已采纳

php在表格中从1到无限的列中排序单元格

i have table with php code like this

name    points

jeme      19
yoka      15
zinga     13

please do it by php code and also no i will give you my code to edit

<?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>

every thing is ok with this table and i ordered names by name who win more points as you see but i still want another column and i will call it [position] and shourcut for it pos. , cause i want to rank user by this way ( numbers 1-2-3-4 ) like this

pos.     name      points

 1       jeme         19
 2       yoka         15
 3       zinga        13
</div>
  • 写回答

1条回答 默认 最新

  • doutangshuan6473 2015-08-20 13:47
    关注

    You can add a column for the position in html. And then, when you parse your sorted data, you can increment a variable like this :

    $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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图