recuperer un nombre implementé dans un tableau

Petit nouveau ! | 3 Messages

16 août 2006, 15:33

Bonjour,

j'ai dans le resultat d'une requete, la 1ere colonne s'implemente automatiquement (i+1) en fonction du nombre de resultat :
exemple :
1. pierre
2. Paul
3. Jacques
4. henry ....


ma question est double... est il possible de n'afficher qu'une ligne en gardant le classement :
exemple :
3. Jacques

et enfin, est il possible d'extraire le classement a un moment donne
Exemple :
pour Henry $i=4

Pour etre plus precis voici mon code :
$i=0;
echo "<tr><td width=120 align=\"center\"><font color=\"#CC9933\"><b>equipe</td></b></font><td width=80 align=\"center\"><font color=\"#CC9933\"><b>Division</td></b></font></tr>";
$sql="SELECT whenisit, plid, tid1
FROM nuke_league_schedule
WHERE score1 IS NULL and sid=$si
order by whenisit ";
    $result = $db->sql_query($sql);
    while($ligne = $db->sql_fetchrow($result)) {
$tid1=$ligne[2];
$plid=$ligne[1];
$i= $i+1;
echo "<tr>
<td width=120 align=\"center\">$i</td>

<td width=120 align=\"center\">". getTeamNamewithURL($tid1, "modules.php?name=League&file=index&op=team&tid=$tid1&sid=$si&lid=$lid") ."</td>
<td width=120 align=\"center\">$plid</td>
</tr>";
}
en resumé pour une team donnée (getTeamNamewithURL) j'aimerai pouvoir extraire le $i correspondant

J'espere avoir été clair :)

Merci

Jim

Eléphant du PHP | 177 Messages

16 août 2006, 16:00

Salut
Je me suis deja prit la tete sur ce genre de probleme et la solution pour laquelle j'ai obté c le rajoute d'un champ dans la base de donnée pour remplir ton $i donc un rajout de plus dans ta requette et un ORDER BY ton nouveau champ un truc dans le genre je dirais ^^

Petit nouveau ! | 3 Messages

16 août 2006, 16:00

pour etre plus precis car la c'est un peu confu, voila ce que je cherche a faire plus concretement :

Je m'occupe d'un site sur un tournoi online. J'ai un module qui me permet de gerer un classement. Sur la base de donnee ne sont notifié que le nombre de victoire, nul defaite, but pour et contre. Le calcul du classement s’effectue par un ensemble de requête SQL ( que j’ai de mal a tout décrypter ) en fonction du nombre de point attribuer a la victoire, nul et defaite….Par exemple, je me retrouve donc avec le tableau suivant :

Joueurs Joués Gagnés Nuls Perdus Pour Contre +/- Pts
1. Milan AC () 9 7 1 1 18 8 10 22
2. FC Seville () 9 5 3 1 16 7 9 18
3. Real Madrid () 9 3 3 3 9 11 -2 12
4. Werder Breme () 8 2 4 2 3 4 -1 10
5. Liverpool () 9 1 3 5 2 8 -6 6
6. Borussia Dortmund () 10 0 4 6 4 14 -10 4

J’aimerai pouvoir récupérer la place d’une équipe en tant que valeur car la elle est implementé automatiquement (p+1)
Exemple : pour le werder $place = 4 pour Seville $place=2

merci

Jimmy

Petit nouveau ! | 3 Messages

17 août 2006, 10:50

Salut,

voila la fonction qui me permet d'afficher la table ($p correspond a l'affichage de la place dans le classement):
function display_division_table($did, $name, $sid, $lid, $disp=1) {
   global $bgcolor1, $bgcolor2;

   $prefs = getLeaguePrefs($lid);

   if ($rowcolor != "")
      $color="bgcolor=\"$prefs[rowcolor]\"";
   else
      $color="";

   $standings = new Standings($lid);
   $max = $standings->size();
   $str = "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" border=\"0\" bgcolor=\"$bgcolor1\">";
   $str .= "<tr><td colspan=\"" . ($max + 3) . "\"><font class=\"option\">$name</font>";
   if (isAdminLeague($lid, ADD_TEAM) and $disp) {
      $str .= "&nbsp;[ <a href=\"modules.php?name=League&file=admin&op=add_team&did=$did&lid=$lid&sid=$sid\">" . _ADDTEAM . "</a> | <a href=\"modules.php?name=League&file=admin&op=recreate_standings_ok&sid=$sid&lid=$lid\">" . _RECREATESTANDING . "</a> | <a href=\"modules.php?name=League&file=admin&op=recalc_standings&sid=$sid&lid=$lid\">" . _RECALCSTANDING . "</a>] ";
                                                          
      $plugin = new Plugins($lid);
      echo $plugin->getLinks(PLUGIN_STANDINGS_DIVISION);
   }
   $str .= "</td></tr>";

   $str .= "<tr><td bgcolor=\"$bgcolor2\"</td><td bgcolor=\"$bgcolor2\" align=\"left\" width=\"36%\"><b>" . _TEAMNAME . "</b></td>";

   $standings = new Standings($lid);
   $maxcol = $standings->size();
   while (($lheader = $standings->headings())) {
      $str .= "<td bgcolor=\"$bgcolor2\" align=\"center\"><b>$lheader</b></td>";
   }
   if ($disp)
      $str .= "<td bgcolor=\"$bgcolor2\">&nbsp;</td>";
   $str .= "</tr>";




   $p=1;
   $standings->select($did, $sid);
   while ($standings->fetchRow()) {
      $tid = $standings->tid();
      if ($bgcolor=="")
         $bgcolor="$color";
      else
         $bgcolor="";

      $str .= "<tr $bgcolor>"
         . "<td align=\"right\" width=\"3%\">$p.</td>"
         . "<td align=\"left\" nowrap width=\"36%\">";
		
      $str .= getTeamNamewithURL($tid, "modules.php?name=League&file=index&op=team&tid=$tid&sid=$sid&lid=$lid&did=$did  ") .     "<i> (" .  getManagerNamesaison($tid, $sid)    .") </i></td>";
      for ($i=0; $i < $standings->size(); $i++) {
         $pos = $standings->position($i);
         $value = $standings->fetchRowValue();
         if ($pos != "")
            $value=$pos;
         $str .= "<td nowrap align=\"center\" nowrap>$value</td>";
      }
      if (isAdminLeague($lid, REMOVE_TEAM) and $disp) {
         $str .= "<td><a href=\"modules.php?name=League&file=admin&op=del_team&tid=$tid&lid=$lid&did=$did&sid=$sid\" title=\"" . _REMOVE . "\"><img src=\"modules/League/images/remove.gif\" border=\"0\" width=\"11\" height=\"11\"></a></td>";
      }
      $str .= "</tr>";
      $p++;
   }


   $str .= "</table>";

   return $str;
}
et voila la fonction qui fait appel a cette fonction
function display_standings($lid, $sid=0) {
   global $db, $prefix;

   include("header.php");

   $sid = zeroIfBlank($sid);

   validateNumForError($lid);
   validateNumForError($sid);

   $prefs = getLeaguePrefs($lid);

   if ($sid == 0)
      $where =  $prefix . "_league.curr_sid = " . $prefix . "_league_season.id";
   else
      $where =  $prefix . "_league_season.id = $sid";

   $result = $db->sql_query("select " . $prefix . "_league.name, " . $prefix . "_league_season.id," . $prefix . "_league_season.name, tournament from " . $prefix . "_league," . $prefix . "_league_season where " . $prefix . "_league.id = " . $prefix . "_league_season.lid and " . $prefix . "_league.id = $lid and $where");
   list($name, $sid, $season, $tournament) = $db->sql_fetchrow($result);

   if ($sid == "") {
      OpenTable();
      echo "<center><b>" . _SEASONNOTSET . "</b></center>";
      CloseTable();     
   }
   else if ($tournament) {
      title(_TOURNAMENT . " - " . stripslashes($name) . " - " . stripslashes($season));
      display_tournament($sid, $lid, "show_round", 0, 0);
   }
   else {
      title(_STANDINGS . " - " . stripslashes($name) . " - " . stripslashes($season));

      OpenTable2();
      echo "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" ;

      $season_selector = display_season_selector($lid, $sid);
      if ($season_selector != "") {
         echo "<tr><td align=\"right\">";
         $plugin = new Plugins($lid);
         echo $plugin->getLinks(PLUGIN_STANDINGS) . " ";
         echo $season_selector;
         echo "</td>";
         echo "</tr>";
         echo "<tr><td><img src=\"modules/League/images/spacer.gif\" border=\"0\" height=\"6\"></td></tr>";
      }

      $result = $db->sql_query("select " . $prefix . "_league_division.id, name from " . $prefix . "_league_division, " . $prefix . "_league_division_seasons where " . $prefix . "_league_division.id = did and tour = 0 and sid = $sid and lid = $lid order by position");
      while (list($did, $name) = $db->sql_fetchrow($result)) {
         echo "<tr><td>";
         OpenTable();
         echo display_division_table($did, stripslashes($name), $sid, $lid);
         CloseTable();
         echo "</td></tr>";
      }
      echo "</table>";
      CloseTable2();
   }

   LeagueFooter($prefs[rightblock], $lid);
}

display_standings($lid, $sid);
Etant debutant j'ai du mal a tout decrypter dans ce code, mais s'il vous faut d'autre fonction, partie de code, demandez :)



Merci
jimmy