AndrewFerrara
AndrewFerrara

Reputation: 2403

Leaderboard from mySQL

How could I add a number starting from 1 to show the leader by total games in this script?

<?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";
  }

?>

Upvotes: 0

Views: 438

Answers (2)

hogni89
hogni89

Reputation: 1754

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

Upvotes: 0

funwhilelost
funwhilelost

Reputation: 2010

You could simply add a variable that increases each time.

  <?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";
  }

  ?>

Upvotes: 4

Related Questions