Numéroter les lignes d'un tableau

Petit nouveau ! | 2 Messages

04 avr. 2008, 09:40

Bonjour, je suis nouveau ici et complétement débutant en PHP. j'arrive à bidouiller certain fichier.
J'aurais besoin d'un service, je viens de créer une asso avec des potes, et j'ai mis en place un systeme d'inscritpion pour des tournois.
Le résultat se fait sous forme de tableau
exemple :
Nom Pseudo Date d'inscription
jean durant toto la date
paul dupont tata la date
eric plan titi la date


mais j'aimerai rajouter le numéro de la ligne au fur et à mesure
exemple
N° Nom Pseudo Date d'inscription
1 jean durant toto la date
2 paul dupont tata la date
3 eric plan titi la date

Voilà le code ou se trouve le résultat du

function displayRegistrations(&$row) {
		global $database, $mosConfig_live_site, $mosConfig_lang, $eSess;
		

		// query for people already registered
		$query  = "SELECT * FROM #__events_registrations ";
		$query .= "WHERE session_id='".$row->session_id."' AND cancel_date='0000-00-00 00:00:00' ";
		$query .= "ORDER BY registration_date ASC";
		$database->setQuery($query);
		$registrants = $database->loadObjectList();


		if (count($registrants) > 0) {
			echo "<h4>" . _ESESS_REG_LIST . "</h4>";
				echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#CC0000\">";
				echo "<tr><td bgcolor=\"#CCCCCC\" width=\"50%\"><b>Nom</b></td>";
			    echo "<td bgcolor=\"#CCCCCC\" width=\"50%\"><b>Pseudo</b></td></tr>";
			    echo "</table>";
			
			
			foreach ($registrants as $registrant) {			
				if ($eSess["cbIntegrated"] && $eSess["showAvatar"]) {
					// Load the avatar picture.  For guests, display the appropriate no_picture file...
					if ($registrant->userid) {
						$query = "SELECT avatar FROM #__comprofiler WHERE user_id='".$registrant->userid."' AND avatarapproved=1";
						$database->setQuery( $query );
						$avatarFileName = $database->loadObjectList();
						if ($avatarFileName[0]->avatar) {
							/* 
							 * Some photos may be from the gallery, while others may be user submitted
							 */
							if (strcmp("gallery", substr($avatarFileName[0]->avatar, 0, 7))) {
								$avatarImgPath = $mosConfig_live_site . "/images/comprofiler/tn" . $avatarFileName[0]->avatar;
							} else {
								$avatarImgPath = $mosConfig_live_site . "/images/comprofiler/" . $avatarFileName[0]->avatar;
							}
						} else {
							$avatarImgPath = $mosConfig_live_site . "/components/com_comprofiler/images/" . $mosConfig_lang . "/tnnophoto.jpg";
						}
					} else {
						$avatarImgPath = $mosConfig_live_site . "/components/com_comprofiler/images/" . $mosConfig_lang . "/tnnophoto.jpg";
					}
					
					echo "<img src=\"" . $avatarImgPath . "\" alt=\"\" align=\"left\" />";
				}
				
				// Display User Details
				echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#CC0000\">";
				echo "<tr><td bgcolor=\"#FFFFFF\" width=\"50%\">";
				echo $registrant->fullname . ""; 
				echo "</td><td bgcolor=\"#FFFFFF\" width=\"50%\">";
				echo $registrant->pseudo . "";
				echo "</td></tr>";
			    echo "</table>";
merci à vous

Eléphant du PHP | 422 Messages

04 avr. 2008, 09:45

Avant ta boucle, tu initialises une variable
$compteur = 0;
Dans ta boucle, tu incrémentes la valeur de la variable et tu l'affiches
$compteur ++;
...
echo $compteur;

Petit nouveau ! | 2 Messages

04 avr. 2008, 10:30

merci beaucoup, ça fonctionne nickel
=D>

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 10684 Messages

04 avr. 2008, 10:41

Modération :
thierryhl, si ta question est résolue, pense à ajouter le tag [Résolu]
pour indiquer aux personnes qui voudront consulter ce sujet qu'il contient une solution.
Tu peux réaliser cette opération en cliquant sur le bouton Image en haut à gauche de ce sujet.
Ce n'est pas en améliorant la bougie que l'on a inventé l'ampoule...