|
|
|
| [PHP] Boucle for et nom de variable ! par elsadelatoundra |
mercredi 25 octobre 2006 à 09:37:23 |
for($i=0; $i < 7 ; $i++){
$post="CHARGES_HH$i";
echo"$i :<BR>- CHARGE_HH = ".$_POST[."'$post'".];
}et à plein d'autre chose, mais rien de tout ce que j'ai pu essayer ne marche ...
Ca devrait marcher normalement.
Et si tu met ce code, ca te marque quoi ?
for($i=0; $i < 7 ; $i++){
$post= "CHARGES_HH".$i;
if ( isset ($_POST[$post]) )
echo "<BR>- CHARGE_HH".$i." = ".$POST[$post];
else
echo "probleme pour CHARGE ".$i;
}
~ iclic @ gauch,iclic, iclic @ droate, iclic, iclic et ya pas de bôg môsieu ! ~ |
Ca me met : probleme pour CHARGE 0probleme pour CHARGE 1probleme pour CHARGE 2probleme pour CHARGE 3probleme pour CHARGE 4probleme pour CHARGE 5probleme pour CHARGE 6
Mince alors ... ellessa mange des cerises |
Ton probleme vient donc bien du nommage de tes inputs :)
Met voir ton code. ~ iclic @ gauch,iclic, iclic @ droate, iclic, iclic et ya pas de bôg môsieu ! ~ |
Je viens de tester ça mais ça ne marche pas non plus ...
for($i=0; $i < 7 ; $i++){
$post= "'CHARGES_HH_".$i."'";
echo$post;
if ( isset ($_POST[$post]) )
echo "<BR>- CHARGES_HH_".$i." = ".$POST[$post];
else
echo "probleme pour CHARGE ".$i;
}
echo"<BR>".$_POST['CHARGES_HH_0'];
En retour j'ai ça : 'CHARGES_HH_0'probleme pour CHARGE 0'CHARGES_HH_1'probleme pour CHARGE 1'CHARGES_HH_2'probleme pour CHARGE 2'CHARGES_HH_3'probleme pour CHARGE 3'CHARGES_HH_4'probleme pour CHARGE 4'CHARGES_HH_5'probleme pour CHARGE 5'CHARGES_HH_6'probleme pour CHARGE 6 10 et 10 correspond bien à ce que j'ai écrit dans mon premier formulaire !! C'est à n'y rien comprendre et je ne comprends rien !! :S ellessa mange des cerises |
modifConso.php
echo"<form action='enregistrementConso.php' method='post'>";
echo"<select name='CHARGES_HH_".$i."' class='form_text'>";
for($j=0; $j <= 9 ; $j++){
echo"<option value='0".$j."'>0".$j."</option>";
echo"\n";
}
echo"<option value='10'>10</option>";
echo"</select>";
enregistrementConso.php for($i=0; $i < 7 ; $i++){
$post= "'CHARGES_HH_".$i."'";
echo$post;
if ( isset ($_POST[$post]) )
echo "<BR>- CHARGES_HH_".$i." = ".$POST[$post];
else
echo "probleme pour CHARGE ".$i;
}
echo"<BR>".$_POST['CHARGES_HH_0'];
Le pire c'est que si je fais ça : $i=1;
foreach ($_POST as $clef){
echo"Clef N° ".$i." = ".$clef."<br>";
$i++;
}
... je peux voir tous mes posts !! Je ne sais pas si mon code t'écalire mais c'est très gentil de ta part de te pencher sur mon problème !! ellessa mange des cerises |
Oups, autant pour moi, remplace :
if ( isset ($_POST[$post]) )
echo "<BR>- CHARGES_HH_".$i." = ".$POST[$post];
par :
if ( isset ($_POST['$post']) )
echo "<BR>- CHARGES_HH_".$i." = ".$POST['$post'];
ou
if (isset ( $_POST["'".$post."'"] ) )
echo "<BR>'CHARGE_HH_".$i." = ".$_POST["'".$post."'"] ;
~ iclic @ gauch,iclic, iclic @ droate, iclic, iclic
et ya pas de bôg môsieu ! ~ |
echo"<form action='enregistrementConso.php' method='post'>";
echo"<select name='CHARGES_HH_".$i."' class='form_text'>";
for($j=0; $j <= 9 ; $j++){
echo"<option value='0".$j."'>0".$j."</option>";
echo"\n";
}
echo"<option value='10'>10</option>";
echo"</select>";
Il te manque pas une boucle là par hasard ?! Ton $i fait référence a quoi ? Met moi tout. ~ iclic @ gauch,iclic, iclic @ droate, iclic, iclic et ya pas de bôg môsieu ! ~
|
Bouh ... aucun des deux !!
if ( isset ($_POST['$post']) )
echo "<BR>- CHARGES_HH_".$i." = ".$POST['$post'];
Les simples quotes autour de $post empêchent son interprétation donc ça ne marche pas ... Et dans le second cas, je ne sais pas ce qui ne marche pas mais j'ai toujours un problème d'interprétation et donc je suis toujours dans le else ... ellessa mange des cerises |
Le pire c'est quand je fais ça :
echo"<BR>".$_POST['CHARGES_HH_0']; echo"<BR>".$_POST['CHARGES_HH_1']; echo"<BR>".$_POST['CHARGES_HH_2']; echo"<BR>".$_POST['CHARGES_HH_3']; echo"<BR>".$_POST['CHARGES_HH_4']; echo"<BR>".$_POST['CHARGES_HH_5']; echo"<BR>".$_POST['CHARGES_HH_6']; Je récupère tous mes posts !! 10 05 04 05 06 06 Notice: Undefined index: CHARGES_HH_6 in c:\program files\easyphp1-8\www\eas_emo\enregistrementconso.php on line 67 Sauf le dernier mais c'est normal ... y a un if qui l'a empêché de se créer !! ellessa mange des cerises |
T'as donc un truc qui ressemble a ca dans ton form :
echo"<form action='enregistrementConso.php' method='post'>";
for ($i=0; $i < 7; $i++){
echo"<select name='CHARGES_HH_".$i."' class='form_text'>";
for($j=0; $j <= 9 ; $j++){
echo"<option value='0".$j."'>0".$j."</option>";
echo"\n";
}
echo"<option value='10'>10</option>";
echo"</select>";
}
echo "<input type='submit' value='go!'>";
echo "</form>";
si je comprends bien... Je vois pas trop ce qui peut clocher, et je suis pas chez moi là donc j'ai pas l'environnement pour faire des tests et débugger :s ~ iclic @ gauch,iclic, iclic @ droate, iclic, iclic et ya pas de bôg môsieu ! ~
|
| 07/11 14h00 | [JavaScript] Boucle for, nom de var + i | Programmation | 08/11 10h22 | 3 |
| 15/06 13h35 | [PHP] boucle for | Webmastering | 15/06 13h41 | 2 |
| 03/07 09h54 | [PHP] boucle for | Programmation | 03/07 16h10 | 4 |
| 02/01 13h02 | php boucle for (help) | Programmation | 03/01 11h36 | 4 |