IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Construction de tableau avec une boucle


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Avril 2008
    Messages
    369
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 369
    Par défaut Construction de tableau avec une boucle
    bonjour,

    Voila dans ma base j'ai 3 périodes différentes dans base_info

    Je souhaiterais faire un tableau par période

    A chaque fois c'est le meme tableau juste les données qui sont différentes

    donc moi j'ai fait quelques lignes pour cette construction mais php ne me construit qu'un seul tableau je voudrais savoir si vous verriez le pourquoi du comment car moi je ne vois pas

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    $sql = "SELECT DATE_DEBUT, DATE_FIN FROM BASE_INFO";
     
    $req = odbc_exec($conn,$sql) or die('Erreur SQL : <br />'.$sql); 
     
    	//--------------- Tableau des informations ouverture et cadence de la période actuelle ---------------// 
    		while (odbc_fetch_row($req)) 
    		{ 
    			$datedeb=odbc_result($req,"DATE_DEBUT"); 
    			$datefin=odbc_result($req,"DATE_FIN");
     
    			list($daystart, $hh)=explode(" ",$datedeb);
    			list($dayend, $hh)=explode(" ",$datefin);
     
    			list($year, $month, $day)=explode("-",$daystart);
    			list($yearfin, $monthfin, $dayfin)=explode("-",$dayend);
     
    			$daystart = $day."-".$month."-".$year;
    			$dayend = $dayfin."-".$monthfin."-".$yearfin;
     
    			echo "<br>"; 
     
    	//--------------- Tableau ---------------// 
     
     
    		//--------------- En tete de colonne ---------------// 
     
    		$jour = array (Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi);			
     
     
    		//--------------- OUVERTURE ---------------// 
     
    		$sql1 = "	SELECT JOUR.JOUR, JOUR.CADENCE, JOUR.OUVERTURE
    					FROM JOUR, BASE_INFO
    					WHERE JOUR.DATE_DEBUT=BASE_INFO.DATE_DEBUT";
     
    		$req = odbc_exec($conn,$sql1) or die('Erreur SQL : <br />'.$sql1);
     
    		while (odbc_fetch_row($req)) 
    			{ 
    			$tab_res[odbc_result($req,"JOUR")]['OUVERTURE']=odbc_result($req,"OUVERTURE"); 
    			$tab_res[odbc_result($req,"JOUR")]['CADENCE']=odbc_result($req,"CADENCE");
    			}
     
    			//------------------ Bouttons ------------------//	
     
    echo "<div style=\"text-align: center;\">";
     
    echo "<input name=\"periode\" value=\"Période prévue\" onclick=\"window.open('Periode_prevue.php', 'utilisateur', config='width=600, height=600, resizable=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes');\" type=\"button\">"; 
     
    	echo "&nbsp &nbsp &nbsp";
     
    echo "<input name=\"periode\" value=\"Mettre a jour une période\" onclick=\"window.open('Formulaire_maj_periode.php', 'utilisateur', config='width=600, height=600, resizable=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no');\" type=\"button\">";
     
    	echo "<br><br>";
     
     
    			$i = 0;
    			while (odbc_fetch_row($req)) 
    			{ 
    			$tab_res[$i]['JOUR'] = odbc_result($req,"JOUR");
    			$tab_res[$i]['OUVERTURE']=odbc_result($req,"OUVERTURE"); 
    			$tab_res[$i++]['CADENCE']=odbc_result($req,"CADENCE");
    			}
     
    //--------------- Tableau des informations ouverture et cadence de la période actuelle ---------------//
    			echo "<table border='0' cellpadding='0' cellspacing='0' width='500'>"; 
    			echo "<tbody>";
    			echo "<table style='width: 500px; height: 90px;' border='5' cellpadding='2' cellspacing='1'>";
    			echo "<tr>"; 
    			echo "<td class='table-titre' colspan='13'> Ouverture et Cadence pour la période du $daystart au $dayend</td>"; 
    			echo "</tr>";
    			//--------------- En tete de colonne ---------------// 
     
    			echo "<tr>"; 
    				echo "<td class='table-entete' width='1'>  </td>"; 
    				echo "<td class='table-entete' width='1'>$jour[0] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[1] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[2]</td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[3] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[4] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[5] </td>";  
    			echo "</tr>";
    			echo "<td class='table-ligne1-centre' width='100'> Ouverture </td>";
    			foreach($tab_res as $ligne)
    			{
    			echo '<td class=\'table-ligne1-centre\' width=\'100\'>'.$ligne['OUVERTURE'].'</td>';
    			}
    			echo "</tr>";
    			echo "<tr>"; 
    			echo "<td class='table-ligne1-centre' width='100'> Cadence </td>"; 
    			foreach($tab_res as $ligne)
    			{
    			echo '<td class=\'table-ligne1-centre\' width=\'100\'>'.$ligne['CADENCE'].'</td>';
    			}
    			echo "</tr>";
    			echo "<tr>"; 
    			echo "<td class='table-ligne1-centre' width='100'> Takt Time </td>"; 
    			foreach($tab_res as $ligne)
    			{
    			$taktime = round($ligne['OUVERTURE']/$ligne['CADENCE'], 2);
    			list($mm, $ss)=explode(".",$taktime);
     
    			$ss = $taktime - $mm;
     
    			$hhtaktime = "00";
    			$sstaktime = $ss*0.6;
    			$total = $mm+$sstaktime;
    			$total = round($total, 2);
    			list($mm, $ss)=explode(".",$total);
    			$total = $hhtaktime.":0".$mm.":".$ss;
    			echo "<td class='table-ligne1-centre' width='100'>$taktime ($total)</td>";
    			}
    			echo "</tr>";
     
    			echo '</table>';
    			echo "</div>"; 	
    		}
    		//--------------- Fin du tableau ---------------// 
     
    echo "<br><br><br>";
    pourriez vous m'aider svp

    merci d'avance

  2. #2
    Membre éclairé
    Inscrit en
    Avril 2008
    Messages
    369
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 369
    Par défaut
    alors désolé pour le double post mais je vous met l'avancé du problème

    donc j'ai maintenant bien mais 3 tableau par contre je ne récupère pas les bonnes valeurs dans les différentes lignes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
     $sql = "SELECT DATE_DEBUT, DATE_FIN FROM BASE_INFO";
     
    $req = odbc_exec($conn,$sql) or die('Erreur SQL : <br />'.$sql); 
     
    	//--------------- Tableau des informations ouverture et cadence de la période actuelle ---------------// 
    		while (odbc_fetch_row($req)) 
    		{ 
    			$datedeb=odbc_result($req,"DATE_DEBUT"); 
    			$datefin=odbc_result($req,"DATE_FIN");
     
     
    			list($daystart, $hh)=explode(" ",$datedeb);
    			list($dayend, $hh)=explode(" ",$datefin);
     
    			list($year, $month, $day)=explode("-",$daystart);
    			list($yearfin, $monthfin, $dayfin)=explode("-",$dayend);
     
    			$daystart = $day."-".$month."-".$year;
    			$dayend = $dayfin."-".$monthfin."-".$yearfin;
     
    			echo "<br>"; 
     
    	//--------------- Tableau ---------------// 
     
     
    		//--------------- En tete de colonne ---------------// 
     
    		$jour = array (Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi);			
     
     
    		//--------------- OUVERTURE ---------------// 
     
    		$sql1 = "	SELECT JOUR.JOUR, JOUR.CADENCE, JOUR.OUVERTURE
    					FROM JOUR, BASE_INFO
    					WHERE JOUR.DATE_DEBUT=BASE_INFO.DATE_DEBUT";
     
    		$req1 = odbc_exec($conn,$sql1) or die('Erreur SQL : <br />'.$sql1);
     
    		while (odbc_fetch_row($req1)) 
    			{ 
    			$tab_res[odbc_result($req1,"JOUR")]['OUVERTURE']=odbc_result($req1,"OUVERTURE"); 
    			$tab_res[odbc_result($req1,"JOUR")]['CADENCE']=odbc_result($req1,"CADENCE");
    			}
     
     
    //--------------- Tableau des informations ouverture et cadence de la période actuelle ---------------//
    			echo "<center>";
     
    			echo "<table border='0' cellpadding='0' cellspacing='0' width='500'>"; 
    			echo "<tbody>";
    			echo "<table style='width: 500px; height: 90px;' border='5' cellpadding='2' cellspacing='1'>";
    			echo "<tr>"; 
    			echo "<td class='table-titre' colspan='13'> Ouverture et Cadence pour la période du $daystart au $dayend</td>"; 
    			echo "</tr>";
    			//--------------- En tete de colonne ---------------// 
     
    			echo "<tr>"; 
    				echo "<td class='table-entete' width='1'>  </td>"; 
    				echo "<td class='table-entete' width='1'>$jour[0] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[1] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[2]</td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[3] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[4] </td>"; 
    				echo "<td class='table-entete-centre' width='20'>$jour[5] </td>";  
    			echo "</tr>";
    			echo "<tr>";
    			echo "<td class='table-ligne1-centre' width='100'> Ouverture </td>";
    			foreach($tab_res as $ligne)
    			{
    			echo '<td class=\'table-ligne1-centre\' width=\'100\'>'.$ligne['OUVERTURE'].'</td>';
    			}
    			echo "</tr>";
    			echo "<tr>"; 
    			echo "<td class='table-ligne1-centre' width='100'> Cadence </td>"; 
    			foreach($tab_res as $ligne)
    			{
    			echo '<td class=\'table-ligne1-centre\' width=\'100\'>'.$ligne['CADENCE'].'</td>';
    			}
    			echo "</tr>";
    			echo "<tr>"; 
    			echo "<td class='table-ligne1-centre' width='100'> Takt Time </td>"; 
    			foreach($tab_res as $ligne)
    			{
    			$taktime = round($ligne['OUVERTURE']/$ligne['CADENCE'], 2);
    			list($mm, $ss)=explode(".",$taktime);
     
    			$ss = $taktime - $mm;
     
    			$hhtaktime = "00";
    			$sstaktime = $ss*0.6;
    			$total = $mm+$sstaktime;
    			$total = round($total, 2);
    			list($mm, $ss)=explode(".",$total);
    			$total = $hhtaktime.":0".$mm.":".$ss;
    			echo "<td class='table-ligne1-centre' width='100'>$taktime ($total)</td>";
    			}
     
    			echo "</tr>";
     
    			echo '</table>';
    			echo "</center>";
    			echo "</div>"; 	
     
    		}
    		//--------------- Fin du tableau ---------------// 
     
    echo "<br><br><br>";
    alors je pense que cela vient de ma boucle while qui est mal placée mais je ne vois pas ou donc si vous pourriez me donné un petit coup de main svp

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     while (odbc_fetch_row($req1)) 
    			{ 
    			$tab_res[odbc_result($req1,"JOUR")]['OUVERTURE']=odbc_result($req1,"OUVERTURE"); 
    			$tab_res[odbc_result($req1,"JOUR")]['CADENCE']=odbc_result($req1,"CADENCE");
    			}

  3. #3
    FoxLeRenard
    Invité(e)
    Par défaut
    Citation Envoyé par drogba72 Voir le message
    alors désolé pour le double post
    Pour moi c' est une question de " ou '
    essais cela
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
     
     
    $sql = "SELECT DATE_DEBUT, DATE_FIN FROM BASE_INFO";
    $req = odbc_exec($conn,$sql) or die('Erreur SQL : <br />'.$sql); 
    		while (odbc_fetch_row($req)) 
    		{ 
    			$datedeb=odbc_result($req,"DATE_DEBUT"); 
    			$datefin=odbc_result($req,"DATE_FIN");
    			list($daystart, $hh)=explode(" ",$datedeb);
    			list($dayend, $hh)=explode(" ",$datefin);
    			list($year, $month, $day)=explode("-",$daystart);
    			list($yearfin, $monthfin, $dayfin)=explode("-",$dayend);
    			$daystart = $day."-".$month."-".$year;
    			$dayend = $dayfin."-".$monthfin."-".$yearfin;
    			echo "<br>"; 
    		$jour = array (Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi);			
    		$sql1 = "	SELECT JOUR.JOUR, JOUR.CADENCE, JOUR.OUVERTURE
    					FROM JOUR, BASE_INFO
    					WHERE JOUR.DATE_DEBUT=BASE_INFO.DATE_DEBUT";
    		$req1 = odbc_exec($conn,$sql1) or die('Erreur SQL : <br />'.$sql1);
    		while (odbc_fetch_row($req1)) 
    			{ 
    			$tab_res[odbc_result($req1,"JOUR")]['OUVERTURE']=odbc_result($req1,"OUVERTURE"); 
    			$tab_res[odbc_result($req1,"JOUR")]['CADENCE']=odbc_result($req1,"CADENCE");
    			}
    			echo "<center>";
    			echo "<table border='0' cellpadding='0' cellspacing='0' width='500'>"; 
    			echo "<tbody>";
    			echo "<table style='width: 500px; height: 90px;' border='5' cellpadding='2' cellspacing='1'>";
    			echo "<tr>"; 
       echo "<td class='table-titre' colspan='13'> Ouverture et Cadence pour la période du ".$daystart." au ".$dayend."</td>"; 
    			echo "</tr>";
    			echo "<tr>"; 
    				echo "<td class='table-entete' width='1'>  </td>"; 
        echo "<td class='table-entete' width='1'>".$jour[0]." </td>"; 
        echo "<td class='table-entete-centre' width='20'>".$jour[1]." </td>"; 
        echo "<td class='table-entete-centre' width='20'>".$jour[2]."</td>"; 
        echo "<td class='table-entete-centre' width='20'>".$jour[3]." </td>"; 
        echo "<td class='table-entete-centre' width='20'>".$jour[4]." </td>"; 
        echo "<td class='table-entete-centre' width='20'>".$jour[5]." </td>";  
    			echo "</tr>";
    			echo "<tr>";
    			echo "<td class='table-ligne1-centre' width='100'> Ouverture </td>";
    			foreach($tab_res as $ligne)
    			{
       echo "<td class='table-ligne1-centre' width='100'>".$ligne['OUVERTURE']."</td>";
    			}
    			echo "</tr>";
    			echo "<tr>"; 
    			echo "<td class='table-ligne1-centre' width='100'> Cadence </td>"; 
    			foreach($tab_res as $ligne)
    			{
       echo "<td class='table-ligne1-centre' width='100'>".$ligne['CADENCE']."</td>";
    			}
    			echo "</tr>";
    			echo "<tr>"; 
    			echo "<td class='table-ligne1-centre' width='100'> Takt Time </td>"; 
    			foreach($tab_res as $ligne)
    			{
    			$taktime = round($ligne['OUVERTURE']/$ligne['CADENCE'], 2);
    			list($mm, $ss)=explode(".",$taktime);
     
    			$ss = $taktime - $mm;
     
    			$hhtaktime = "00";
    			$sstaktime = $ss*0.6;
    			$total = $mm+$sstaktime;
    			$total = round($total, 2);
    			list($mm, $ss)=explode(".",$total);
    			$total = $hhtaktime.":0".$mm.":".$ss;
       echo "<td class='table-ligne1-centre' width='100'>".$taktime ($total)."</td>";
    			}
     
    			echo "</tr>";
     
    			echo '</table>';
    			echo "</center>";
    			echo "</div>"; 	
     
    		}
    echo "<br><br><br>";

  4. #4
    Membre éclairé
    Inscrit en
    Avril 2008
    Messages
    369
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 369
    Par défaut
    hélas ce que tu as modifié ne change rien mais ce n'est pas facile a comprendre comme problème

    je te met un imprim ecran pour te faire voir que les périodes sont différente mais l'ouverture et la cadence sont la même

    http://www.imagefreehost.com/files/2...2443931363.bmp

  5. #5
    FoxLeRenard
    Invité(e)
    Par défaut
    Citation Envoyé par drogba72 Voir le message
    hélas ce que tu as modifié ne change rien mais ce n'est pas facile a comprendre comme problème

    je te met un imprim ecran pour te faire voir que les périodes sont différente mais l'ouverture et la cadence sont la même

    http://www.imagefreehost.com/files/2...2443931363.bmp
    OK avec ton image, je comprends trés bien, du coup je refile décortiquer tes boucles voir si je trouves,

    A bientôt si j'ais la chance

  6. #6
    Membre éclairé
    Inscrit en
    Avril 2008
    Messages
    369
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 369
    Par défaut
    lol merci pour ton soutien

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. remplir un tableau avec une boucle while
    Par supcomingenieur dans le forum Langage
    Réponses: 12
    Dernier message: 03/05/2013, 09h54
  2. implementer un tableau avec une boucle for
    Par shimomura22 dans le forum C#
    Réponses: 14
    Dernier message: 14/01/2011, 16h22
  3. Présentation d'un tableau avec une boucle for()
    Par Jarodd dans le forum Langage
    Réponses: 2
    Dernier message: 19/12/2008, 11h39
  4. [PHP 5.0] Complèter un tableau avec une boucle "for"
    Par kriekbellevue dans le forum Langage
    Réponses: 1
    Dernier message: 07/12/2008, 22h04
  5. Construction Tableau avec une boucle
    Par fred_hot dans le forum Langage
    Réponses: 6
    Dernier message: 08/09/2008, 11h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo