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

时间:2015-08-20 13:38:06

标签: php sorting numbers position

我有像这样的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>

请通过php代码完成,也不,我会给你我的代码编辑

pos.     name      points

 1       jeme         19
 2       yoka         15
 3       zinga        13

这个表格的每件事情都没问题,我按照名字命名了名字,如你所见,我仍然想要更多的积分,但我仍然想要另一个专栏,我会称之为[位置]并为它提供奖励。因为我想通过这种方式对用户进行排名(数字1-2-3-4),就像这样

Sub dts()
    Dim Date1 As Date, Date2 As Date

    Date1 = DateSerial(2014, 7, 31)
    Date2 = DateSerial(2014, 8, 1)
    Debug.Print CBool(Abs((Month(Date1) - (Month(Date1) = 1) * 12) - (Month(Date2) - (Month(Date2) = 1) * 12)) = 1)

    Date1 = DateSerial(2007, 12, 31)
    Date2 = DateSerial(2016, 1, 1)
    Debug.Print CBool(Abs((Month(Date1) - (Month(Date1) = 1) * 12) - (Month(Date2) - (Month(Date2) = 1) * 12)) = 1)

    Date1 = DateSerial(2014, 7, 31)
    Date2 = DateSerial(2014, 9, 1)
    Debug.Print CBool(Abs((Month(Date1) - (Month(Date1) = 1) * 12) - (Month(Date2) - (Month(Date2) = 1) * 12)) = 1)

End Sub

1 个答案:

答案 0 :(得分:0)

您可以在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