来自mySQL的排行榜

时间:2011-02-20 02:35:20

标签: php mysql

如何从1开始添加一个数字,以便通过此脚本中的总游戏来显示领导者?

<?php

$result = mysql_query("SELECT gamertag, tgames FROM leader ORDER BY tgames DESC");

while ($row = mysql_fetch_assoc($result)) {
  echo "number? ".$row['gamertag']." ".$row['tgames']."<br>\n";
  }

?>

2 个答案:

答案 0 :(得分:4)

您只需添加一个每次都增加的变量。

  <?php

  $result = mysql_query("SELECT gamertag, tgames FROM leader ORDER BY tgames DESC");

  $index = 1;
  while ($row = mysql_fetch_assoc($result)) {
    echo $index++ . " " . $row['gamertag'] . " " . $row['tgames'] . "<br>\n";
  }

  ?>

答案 1 :(得分:0)

(...)
$i = 1;
while($row = mysql_fetch_assoc($result)) {
    echo $i . " " .$row['gamertag']." ".$row['tgames']."<br>\n";
    $i++;
}