|
|
|
|
[PHP] Boucle for et nom de variable !
Dernière réponse le 10 nov 2008 à 18:05:13 elsadelatoundra, le 25 oct 2006 à 09:37:23Bonjour ...
J'ai 7 inputs portant les noms suivants :
CHARGES_HH0
CHARGES_HH1
CHARGES_HH2
CHARGES_HH3
CHARGES_HH4
CHARGES_HH5
CHARGES_HH6
Je vous rassure, c'est construit à l'aide d'une boucle for !!
Je suis dans un formulaire method='post' et je veux récupérer ces valeurs dans un autre formulaire... je voudrais le faire à l'aide d'une boucle for mais je n'y arrive pas du tout !!
Si quelqu'un a une idée, il me sauve la vie !
Moi j'avais pensé à faire quelque chose de ce style :
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 ...
Je vous remercie d'avance pour votre aide qui me sera très précieuse !!
ellessa mange des cerises
Ca devrait marcher normalement.
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 ! ~ |
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 ! ~
|

