Rang classement PHP

Bonjour, Voici mon problème :

J'ai un tableau :
____________________
| Rang | Pseudo | Points |
----------------------------
| | Marc | 58 |
----------------------------
| | Michel | 23 |
----------------------------
| | Max | 7 |
----------------------------

Et je souhaiterais que dans ma colonne "Rang", à chaque ligne apparaisse un nombre, première ligne : 1, deuxième : 2 troisième : 3 etc...

C'est à dire ça :
____________________
| Rang | Pseudo | Points |
----------------------------
| 1 | Marc | 58 |
----------------------------
| 2 | Michel | 23 |
----------------------------
| 3 | Max | 7 |
----------------------------

Merci d'avance pour votre aide.

5 réponses

  1. Il te suffit de gerer un petit compteur ...

    //Init
    $compteur=0;

    while($dnn = mysql_fetch_array($req))
    {
    $compteur++;
    ?>

    <tr>
    <td><?php echo $compteur; ?></td>
    <td><a href="profilparc.php?id=<?php echo $dnn['userid']; ?>"><?php echo htmlentities($dnn['username']); ?></td>
    <td><?php echo htmlentities($dnn['level']); ?></a></td>
    <td><?php echo htmlentities($dnn['argent']); ?></td>
    <td><?php echo htmlentities($dnn['points']); ?></td>
    <td><?php echo htmlentities($dnn['nbescargot']); ?></td>
    </tr>

    <?php
    }
    /* Reinitialisation du compteur pour etre utiliser dans un autre tableau */
    $compteur=0;

    Hope it helps
    Cube
    1
    1. Contributeur
      Bonjour,

      Quel logiciel et/ou langage ?
      0
      1. Bonjour
        Oui, mais la question est comment tu as les données ?

        Affiche tu un tableau php ? Si oui, donne ton code, il faut juste un sort a mon avis ...
        Recupere tu des donnees SQL ? De meme donne le code, dans la command SQL, tu peux ordonner tes donnees.
        Cube
        0
        1. <table class="profil">
             
              <tr>
                  <td>Rang</td>
                  <td>Pseudo</td>
                  <td>Niveau</td>
          		<td>Argent</td>
          		<td>Points</td>
          		<td>Nombre d'escargot</td>
              </tr>
             <?php
          $req = mysql_query('select username, userid, level, nbescargot, argent, points from escargot ORDER BY level DESC');
          
          while($dnn = mysql_fetch_array($req))
          {
          ?>
                   
          <tr>
          <td>ICI LE RANG</td>
          <td><a href="profilparc.php?id=<?php echo $dnn['userid']; ?>"><?php echo htmlentities($dnn['username']); ?></td>
          <td><?php echo htmlentities($dnn['level']); ?></a></td>
          <td><?php echo htmlentities($dnn['argent']); ?></td>
          <td><?php echo htmlentities($dnn['points']); ?></td>
          <td><?php echo htmlentities($dnn['nbescargot']); ?></td>
          </tr>
          
              
          <?php
          }
          ?>
          </table>
          0