Afficher une fonction

Invité
Invité n'ayant pas de compte PHPfrance

03 sept. 2005, 06:41

Bonjour à tous. J'aurais besoin de votre aide pour afficher une fonction.

Actuellement, la donnée s'affiche comme cela :

Paris : 2
Metz : 0

J'aimerais que cela s'affiche comme ça :

(Paris - Metz : 2-0)

Voici mon bout de code :

Code : Tout sélectionner

function display_detail_game($schid, $tid1, $tid2, $team1, $team2, $display=0) { $thelid = getLid($schid); $game = new Games($thelid); $game->setTid1($tid1); $game->setTid2($tid2); if ($game->ok()) { $game->summaryTeam1($schid); $game->summaryTeam2($schid); if ((($game->summaryTeam1OK()) && ($game->summaryTeam2OK())) || ($display == 0)) { while (($lheader = $game->headings())) { } $game->printTeam1Summary($display); $game->printTeam2Summary($display); } } }
Merci :wink:

Invité
Invité n'ayant pas de compte PHPfrance

04 sept. 2005, 11:09

Personne ne peut me venir en aide svp ?

Mammouth du PHP | 19672 Messages

04 sept. 2005, 11:20

Ton code fait appel à des classes externes or il semble que l'affichage soit géré par une de ces classes : difficile de t'aider sans voir les méthodes de classes utilisées.
Codez en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse :axe:

Invité
Invité n'ayant pas de compte PHPfrance

05 sept. 2005, 09:49

Cela ressemble à quoi les classes pour que je puise les mettre sur le forum ?

Eléphanteau du PHP | 28 Messages

05 sept. 2005, 10:02

Tu dois avoir quelque part dans ton code (pas forcément sur la même page dont est issu ton code précédent... ce n'est même sûrement pas le cas) un morceau qui ressemble à ça :
class Games 
{
    .
    .
    .
}
C'est ce code là que tu dois afficher (il est possible que la classe soit dans un fichier ou un dossier dont le nom comporte le terme "class". Mais je ne garantis rien)

Invité
Invité n'ayant pas de compte PHPfrance

05 sept. 2005, 12:52

Je pense alors que c'est ce code ci-dessous. Que dois-je modifier ?

Code : Tout sélectionner

/* * Game Summary table */ class Games extends dynamicTable { var $data_index; var $tid1; var $tid2; var $data_team1_result; var $data_team2_result; var $data_team1; var $data_team2; function Games($lid) { global $prefix, $db; $this->result = $db->sql_query("select * from " . $prefix . "_league_schedule_summary_setup where lid = $lid"); $this->setup = $db->sql_fetchrow($this->result); $this->rows = $db->sql_numrows($this->result); $c=0; for ($i=2;$i < 13; $i++) { if ($this->setup[$i] != "") $c++; } $this->size = $c; $this->index = 2; $this->start = 2; }
Merci pour votre aide :wink:

Eléphanteau du PHP | 28 Messages

05 sept. 2005, 13:09

C'est bien cela, mais peux-tu afficher le code de la classe dynamicTable désormais ?

Invité
Invité n'ayant pas de compte PHPfrance

05 sept. 2005, 13:23

Oui je peux le faire :lol: :lol: :wink:

Code : Tout sélectionner

/* * Generic class to create dynamicTables */ class dynamicTable { var $result; var $setup; var $size; var $index; var $pos; var $calcStart; var $rows; var $start; /* * Return the ID of the setup row */ function id() { return $this->setup['id']; } /* * The number of headers */ function size() { return $this->size; } function ok() { return ($this->rows > 0); } /* * Return the next heading */ function headings($i=-1) { if ($i == -1) { if ($this->setup[$this->index] != "") { $this->index++; return ($this->setup[$this->index-1]); } else return false; } return ($this->setup[$i+2]); } /* * See if we have a calculated field */ function ifCalc($i) { return ($this->setup[$i+$this->calcStart]!=""); } /* * Return the calculated field */ function calc($i) { return ($this->setup[$i+$this->calcStart - 1]); } /* * Return the postion number of the standing */ function position($i) { if ($this->setup[$i+$this->calcStart]=="pos") { $origpos = $this->pos; $this->pos++; return $origpos; } return ""; } /* * Get a row of data for this dynamic table */ function fetchRow(&$data_result, &$data) { global $db; $data = $db->sql_fetchrow($data_result); if (empty($data)) { return false; } return (true); } /* * Return the next data value from a row of data */ function fetchRowValue(&$data_index, &$data, $start, $i=0) { $index = $data_index; $index2 = $index + 1; if ($i == 0) { if ($data[$index] != "") { $data_index = $index2; return ($data[$index]); } } return ($data[$i + $start]); } }

Invité
Invité n'ayant pas de compte PHPfrance

06 sept. 2005, 22:46

Quelqu'un peut venir à mon secours svp ?

Mammouth du PHP | 19672 Messages

07 sept. 2005, 08:44

La classe Games est incomplète... il en manque à priori un bout, vérifie et reviens confirmer ou non.
Codez en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse :axe:

Invité
Invité n'ayant pas de compte PHPfrance

07 sept. 2005, 09:11

Ca doit être par là alors :wink:
/*
 * Generic class to create dynamicTables
 */

class dynamicTable {
   var $result;
   var $setup;
   var $size;
   var $index;
   var $pos;
   var $calcStart;
   var $rows;
   var $start;

   /*
    * Return the ID of the setup row
    */

   function id() {
      return $this->setup['id'];
   }

   /*
    * The number of headers
    */

   function size() {
      return $this->size;
   }

   function ok() {
      return ($this->rows > 0);
   }

   /*
    * Return the next heading
    */

   function headings($i=-1) {

      if ($i == -1) {
         if ($this->setup[$this->index] != "") {
            $this->index++;
            return ($this->setup[$this->index-1]);
         }
         else
            return false;
      }

      return ($this->setup[$i+2]);
   }

   /*
    * See if we have a calculated field
    */

   function ifCalc($i) {
      return ($this->setup[$i+$this->calcStart]!=""); 
   }


   /*
    * Return the calculated field 
    */

   function calc($i) {
      return ($this->setup[$i+$this->calcStart - 1]);
   }

   /* 
    * Return the postion number of the standing
    */

   function position($i) {
      if ($this->setup[$i+$this->calcStart]=="pos") {
         $origpos = $this->pos;
         $this->pos++;
         return $origpos;
      }
      return "";
   }

   /*
    * Get a row of data for this dynamic table
    */

   function fetchRow(&$data_result, &$data) {
      global $db;

      $data = $db->sql_fetchrow($data_result);

      if (empty($data)) {
         return false;
      }

      return (true);
   }

   /*
    * Return the next data value from a row of data
    */

   function fetchRowValue(&$data_index, &$data, $start, $i=0) {
      $index = $data_index;
      $index2 = $index + 1;

      if ($i == 0) {
         if ($data[$index] != "") {
            $data_index = $index2;
            return ($data[$index]);
         }
      }
      return ($data[$i + $start]);
   }
}

/*
 * Stanndings tables
 */

class Standings extends dynamicTable {
   var $data;
   var $data_index;
   var $data_result;

   function Standings($lid) {
      global $prefix, $db;

      $this->result = $db->sql_query("select * from " . $prefix . "_league_standings_setup where lid = $lid");
      $this->setup = $db->sql_fetchrow($this->result);
      $this->rows = $db->sql_numrows($this->result);

      $c=0;
      for ($i=2; $i < 17; $i++) {
         if ($this->setup[$i] != "")
            $c++;
         else
            break;
      }
      $this->size = $c;
      $this->start = 2;
      $this->index = 2;
      $this->pos = 1;
      $this->calcStart=17;
   }

   function size() {
      return ($this->size);
   }

   function select($did, $sid, $limit=0, $tid=0) {
      global $prefix, $db;

      if ($did != 0)
         $select_did = " and " . $prefix . "_league_team_seasons.did = $did ";
      else
         $select_did = "";

      $select = "select " . $prefix . "_league_teams.id as tid, " . $prefix . "_league_standings.id as stdid,";
      $j=1;
      for ($i=$this->calcStart; $i < $this->size+$this->calcStart; $i++) {
         if ($this->setup[$i] != "") {
            if ($this->setup[$i] == "pos")
               $select .= "1 as std$j,";
            else
               $select .= eregi_replace("col","std",$this->setup[$i]) . " as std$j,";
         }
         else {
            $select .= "std$j,";
         }
         $j++;
      }
      $select = substr($select, 0, strlen($select)-1);

      $select .= " from " . $prefix . "_league_team_seasons, " . $prefix . "_league_teams," . $prefix . "_league_standings where " . $prefix . "_league_teams.id = " . $prefix . "_league_standings.tid and " . $prefix . "_league_standings.sid = $sid and " . $prefix . "_league_team_seasons.sid = " . $prefix . "_league_standings.sid and " . $prefix . "_league_teams.id = " . $prefix . "_league_team_seasons.tid $select_did";

      if ($tid != 0)
         $select .= "and " . $prefix . "_league_teams.id = $tid ";

      $by = "";
      $order = "";
      if ($this->setup['sort1'] > 0) {
         $order = "order by ";
         $by .= "std" . $this->setup['sort1'] . " desc,";
      }
      if ($this->setup['sort2'] > 0) {
         $order = "order by ";
         $by .= "std" . $this->setup['sort2'] . " desc,";
      }
      if ($this->setup['sort3'] > 0) {
         $order = "order by ";
         $by .= "std" . $this->setup['sort3'] . " desc,";
      }
      if (strlen($order) > 0) {
         $by = substr($by, 0, strlen($by)-1);
         $select .= "$order $by";
      }
      if ($limit > 0)
         $select .= " limit $limit";

//echo "$select<br><br>";
      $this->data_result = $db->sql_query($select);
   }

   function fetchSetupSort() {

      $row = array();
      $row[0] = $this->setup['sort1'];
      $row[1] = $this->setup['sort2'];
      $row[2] = $this->setup['sort3'];

      return ($row);
   }

   function fetchSetupGame() {

      $row = array();
      $row[0] = $this->setup['W'];
      $row[1] = $this->setup['T'];
      $row[2] = $this->setup['L'];
      $row[3] = $this->setup['PF'];
      $row[4] = $this->setup['PA'];

      return ($row);
   }

   function fetchRowStdid() {
      return ($this->data['stdid']);
   }

   function fetchRow() {
      $ret = dynamicTable::fetchRow($this->data_result, $this->data);
      if ($ret)
         $this->data_index = 2;
      else
         $this->data_index = 0;
      
      return $ret;
   }

   function fetchRowValue($i=0) {
      return dynamicTable::fetchRowValue($this->data_index, $this->data, 
                                  $this->start, $i);
   }

   function tid() {
      return $this->data['tid'];
   }
}

/*
 * Game Summary table
 */

class Games extends dynamicTable {
   var $data_index;
   var $tid1;
   var $tid2;
   var $data_team1_result;
   var $data_team2_result;
   var $data_team1;
   var $data_team2;

   function Games($lid) {
   global $prefix, $db;

      $this->result = $db->sql_query("select * from " . $prefix . "_league_schedule_summary_setup where lid = $lid");
      $this->setup = $db->sql_fetchrow($this->result);
      $this->rows = $db->sql_numrows($this->result);

      $c=0;
      for ($i=2;$i < 13; $i++) {
         if ($this->setup[$i] != "")
            $c++;
      }

      $this->size = $c;
      $this->index = 2;
      $this->start = 2;
   }

   function select($schid, $tid) {
      global $prefix, $db;

      $result = $db->sql_query("select * from " . $prefix . "_league_schedule_summary where schid = $schid and tid = $tid");
      return ($result);
   }

   function fetchRow(&$result, &$data) {
      $ret = dynamicTable::fetchRow($result, $data);
      if ($ret)
         $this->data_index = 3;
      else
         $this->data_index = 0;
      
      return $ret;
   }

   function setTid1($tid) {
      $this->tid1 = $tid;
   }

   function setTid2($tid) {
      $this->tid2 = $tid;
   }

   function fetchRowValueTeam(&$data, $i) {
      return dynamicTable::fetchRowValue($this->data_index, $data, 
                                  $this->start, $i, 1);
   }

   function summaryTeam1($schid) {
      $this->data_team1_result = $this->select($schid, $this->tid1);
      $this->fetchRow($this->data_team1_result, $this->data_team1);
   }

   function summaryTeam2($schid) {
      $this->data_team2_result = $this->select($schid, $this->tid2);
      $this->fetchRow($this->data_team2_result, $this->data_team2);
   }

   function summaryTeamOK($team_data) {
      for($i=1; $i <= $this->size+1; $i++) {
         $val = $this->fetchRowValueTeam($team_data, $i);
         if ($val != "")
            return 1;
      }

      return 0;
   }

   function summaryTeam1OK() {
      return ($this->summaryTeamOK($this->data_team1));
   }

   function summaryTeam2OK() {
      return ($this->summaryTeamOK($this->data_team1));
   }

   function printTeamSummary($team, $data, $id, $display=1) {
      echo "<tr>";
      echo "<td align=\"right\" nowrap><b>" . $team . ":</b>&nbsp;</td>";
      for ($i=1;$i <= $this->size(); $i++) {
         $value = $this->fetchRowValueTeam($data, $i);
         echo "<td align=\"center\">";
         if ($display == 1)
            echo "$value";
         else
            echo "<input type=\"text\" name=\"team" . $id . "_period[$i]\" value=\"$value\" size=\"2\">";
         echo "</td>";
      }
      echo "</tr>";
   }

   function printTeam1Summary($display) {
      $this->printTeamSummary(getTeamName($this->tid1), $this->data_team1, "1", $display);
   }

   function printTeam2Summary($display) {
      $this->printTeamSummary(getTeamName($this->tid2), $this->data_team2, "2", $display);
   }
}

Mammouth du PHP | 19672 Messages

07 sept. 2005, 09:36

J'adore le code pas commenté du tout :? : C'est toi qui as pondu ces classes ? Je présume que non, tu l'as téléchargé avec un kit complet : tu as un lien vers le site ?
Codez en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse :axe:

Invité
Invité n'ayant pas de compte PHPfrance

09 sept. 2005, 12:10

Le code n'est pas de moi.

Je pense que pour modifier l'apparence ce qui nous interesse est :

$game->printTeam1Summary ($display) ; $game->printTeam2Summary($display);

Ce code affiche comme ça :

Paris : 2
Metz : 0

Dans classes.php il y a ça :

function printTeam1Summary($display) {
$this->printTeamSummary(getTeamName($this->tid1), $this->data_team1, "1", $display);
}

function printTeam2Summary($display) {
$this->printTeamSummary(getTeamName($this->tid2), $this->data_team2, "2", $display);
}

Je voudrais que cela s'affiche comme ça :

Mi-temps : 2-0

Qui peut me sauver la mise svp

Mammouth du PHP | 19672 Messages

09 sept. 2005, 14:01

Difficile sans avoir l'ensemble des classes. Tu as téléchargé ça où ? À priori, il y a soit une méthode à ré-écrire soit une surcharge à concevoir.
Codez en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse :axe:

Modérateur PHPfrance
Modérateur PHPfrance | 7636 Messages

09 sept. 2005, 14:18

Salut, j'ai pas testé mais en remplaçant les 3 dernières fonctions comme ceci, peut etre que ca marchera ( avec un peu de chance [-o< )
function printTeamSummary($team, $data, $id, $display=1,$passage) 
{
      
	  if($passage == 1)
		{
			echo "<tr>";		
			echo "<td align=\"right\" nowrap><b>" . $team . ":</b>&nbsp;</td>";
		}
	   
      for ($i=1;$i <= $this->size(); $i++) {
         $value = $this->fetchRowValueTeam($data, $i);
         echo "<td align=\"center\">";
         if ($display == 1)
            {
				echo "$value";
				if($passage == 1)
					echo ' : ';
			}
         else
            echo "<input type=\"text\" name=\"team" . $id . "_period[$i]\" value=\"$value\" size=\"2\">";
         echo "</td>";
      }
      if($passage == 2)
		{
			echo "<td align=\"right\" nowrap><b>" . $team . ":</b>&nbsp;</td>";
			echo "</tr>";
		}
   }

   function printTeam1Summary($display) {
      $this->printTeamSummary(getTeamName($this->tid1), $this->data_team1, "1", $display,1);
   }

   function printTeam2Summary($display) {
      $this->printTeamSummary(getTeamName($this->tid2), $this->data_team2, "2", $display,2);
   } 
sinon j'en sais pas plus, en tout cas je ne vois pas d'autre endroits ou ça "affiche".