Rang classement PHP

Ulrich7 -  
CubeRCL Messages postés 9 Statut Membre -
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.



A voir également:

5 réponses

CubeRCL Messages postés 9 Statut Membre 2
 
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
michel_m Messages postés 18903 Statut Contributeur 3 318
 
Bonjour,

Quel logiciel et/ou langage ?
0
Ulrich7
 
Oups, c'est du PHP :)
0
CubeRCL Messages postés 9 Statut Membre 2
 
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

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Ulrich7
 
<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