Ajout d'une élément dans un tableau PHP

Résolu/Fermé
Mikius_92 Messages postés 35 Date d'inscription vendredi 26 janvier 2007 Statut Membre Dernière intervention 28 février 2007 - 26 janv. 2007 à 13:42
Mikius_92 Messages postés 35 Date d'inscription vendredi 26 janvier 2007 Statut Membre Dernière intervention 28 février 2007 - 31 janv. 2007 à 09:22
Mon idée c’est quand que je sélectionne Oui en cliquant sur le bouton Valider

Il faut que le fonction ajoute le chiffre 1 dans le champs Qté de la boucle For.

Et si je sélectionne Non alors le chiffre 0 s’affiche dans le champs Qté.



Voici mon code :



$strCmd .= "<script language = 'Javascript'>";

$strCmd .= "function choix(bouton){";

$strCmd .= "if (bouton.checked)";

$strCmd .= "{";

$strCmd .= "alert(bouton.value)";

$strCmd .= "}";

$strCmd .= "}";

$strCmd .= "</script>";



$strCmd .= "<td align='center' class='affich'>\n";

$strCmd .= "<form >";

$strCmd .= "<input type='radio' name='choix_".$i."' value='Oui' onchange='choix(this)'> Oui<br>";

$strCmd .= "<input type='radio' name='choix_".$i."' value='Non' onchange='choix(this)'> Non<br>";

$strCmd .= "<input type='button' value='valider' name='valider($i)'onclick= 'choix($i)'>";

$strCmd .= "</form>";

$strCmd .= "</td>\n";



J’effectue cette opération où dans la fonction.

Merci.
A voir également:

3 réponses

kij_82 Messages postés 4088 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013 857
26 janv. 2007 à 13:55
Tu ne peux pas être plus 'précis' quand tu dis :
dans le champs Qté de la boucle For


C'est quoi Qté ? Un champ caché que tu veux dans ton formulaire ?
Boucle For, t'entends quoi par là, où as tu une boucle for ?

Bon, si c'est la première chose que tu veux faire, c'est à dire mettre à jour la valeur d'un champ caché qui sera passé à ton formulaire alors voici la modification :


$strCmd .= "<script language = 'Javascript'>"; 

$strCmd .= "function choix(bouton){"; 

$strCmd .= "if (bouton.checked)"; 

$strCmd .= "{"; 

$strCmd .= "if (bouton.value == "Oui" ){ document.getElementById('Qte').value = 1;}else{document.getElementById('Qte').value = 0;}";

$strCmd .= "}"; 

$strCmd .= "}"; 

$strCmd .= "</script>"; 



$strCmd .= "<td align='center' class='affich'>\n"; 

$strCmd .= "<form >"; 

$strCmd .= "<input type="hidden" name="Qte" id="Qte" value="0" >"; 

$strCmd .= "<input type='radio' name='choix_".$i."' value='Oui' onchange='choix(this)'> Oui<br>"; 

$strCmd .= "<input type='radio' name='choix_".$i."' value='Non' onchange='choix(this)'> Non<br>"; 

$strCmd .= "<input type='button' value='valider' name='valider($i)'onclick= 'choix($i)'>"; 

$strCmd .= "</form>"; 

$strCmd .= "</td>\n"; 




Mais à quoi ca te sert de mettre le code de ta page dans "$strCmd " au juste ?
0
Mikius_92 Messages postés 35 Date d'inscription vendredi 26 janvier 2007 Statut Membre Dernière intervention 28 février 2007
26 janv. 2007 à 13:59
Non c'est pas un champs caché je veux mettre à jour le champs Qté (Quantité) de mon tableau à jour en fonction de mes boutons radios

$strCmd c'est la variable php où je crée mon tableau etc....
0
kij_82 Messages postés 4088 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013 857
26 janv. 2007 à 14:02
de mon tableau 

Et il est ou ce fameux tableau ? Tu as autre chose comme code qui pourrait nous être utile pour comprendre ?
0
Mikius_92 Messages postés 35 Date d'inscription vendredi 26 janvier 2007 Statut Membre Dernière intervention 28 février 2007 > kij_82 Messages postés 4088 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013
26 janv. 2007 à 14:03
ok le voici

//Affichage des pièces
$strCmd="<br>
<table class='boxtitle' width='100%' border='1' BORDERCOLOR='#000000' bgcolor='white' cellpadding='0' cellspacing='0'>\n";
If ($_SESSION['entreprise_active']!= 'BMA')
{
$strCmd.="<tr>\n
<td>PIECES INTERVENTION</td>\n
<td><img src=\"../../images/changer.jpg\" height=\"22\" border=\"0\" onclick=\"popup_pieces('$numaffaire','$nomdo')\" alt=\"\" title=\"Gestion des pièces\" onmouseover=\"this.style.cursor='hand'\" width=\"22\" /></td>
</tr>\n";
}
$strCmd.=" <tr> \n
<td width='1%' align='center'>Fournisseur</td>\n
<td width='1%' align='center'>Référence</td>\n
<td width='1%' align='center'>Désignation</td>\n
<td width='1%' align='center'>Type Stock</td>\n
<td width='1%' align='center'>Qté Cde</td>\n
<td width='1%' align='center'>Qté</td>\n
<td width='1%' align='center'>Conso</td>\n
<td width='1%' align='center'>Date Conso</td>\n
<td width='1%' align='center'>N° Cde</td>\n
<td width='1%' align='center'>Express</td>\n
<td width='1%' align='center'>Date Cde</td>\n
<td width='1%' align='center'>Date Liv</td>\n
<td width='1%' align='center'>Agence Cde</td>\n
</tr>\n";

for ($i=0;$i<$Nbpieces;$i++)
{

$strCmd .= "<tr>";
$strCmd .= "<td align='center' class='affich'>\n";

if ($Tabpieces[$i]['sst_libelle'] == "STOCK CENTRAL")
{
$strCmd .= "Call Center";
}
else
{
$strCmd .= Ucwords(strtolower($Tabpieces[$i]['nom_cf']));
}
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['reference'];
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['designation'];
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['sst_libelle'];
$strCmd .= "</td>";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['qte_cdee'];
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['qte'];
$strCmd .= "</td>\n";

$strCmd .= "<script language = 'Javascript'>";
$strCmd .= "function choix(bouton){";
$strCmd .= "if (bouton.checked)";
$strCmd .= "{";
$strCmd .= "if (bouton.value == "Oui" ){document.getElementById('Qte').value = 1;}";
$strCmd .= "else{document.getElementById('Qte').value = 0;}";
$strCmd .= "}";
$strCmd .= "}";
$strCmd .= "</script>";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= "<form >";
$strCmd .= "<input type='radio' name='choix_".$i."' value='Oui' onchange='choix(this)'> Oui<br>";
$strCmd .= "<input type='radio' name='choix_".$i."' value='Non' onchange='choix(this)'> Non<br>";
$strCmd .= "<input type='button' value='valider' name='valider($i)'onclick= 'choix($i)'>";
$strCmd .= "</form>";
$strCmd .= "</td>\n";

/*$strCmd .= "<script language = 'Javascript'>";
$strCmd .= "function choix(bouton){";
$strCmd .= "alert(bouton.value)";
$strCmd .= "}";
$strCmd .= "</script>";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= "<form name='formulaire_".$i."'>";
$strCmd .= "<input type='radio' name='choix_".$i."' value='Oui'> Oui<br>";
$strCmd .= "<input type='radio' name='choix_".$i."' value='Non'> Non<br>";
$strCmd .= "<input type='button' value='valider' name='valider_".$i."' onclick= 'choix(formulaire_".$i.".choix_".$i.")'>";
$strCmd .= "</form>";
$strCmd .= "</td>\n";*/

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['datepieceenvoi'];
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['num_cde'];
$strCmd .= "</td>\n";


$strCmd .= "<td align='center' class='affich'>\n";
if ($Tabpieces[$i]['express'] == 1)
{
$strCmd .= "X";
}
else
{
$strCmd .= "";
}
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['datecde'];
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['datelivr'];
$strCmd .= "</td>\n";

$strCmd .= "<td align='center' class='affich'>\n";
$strCmd .= $Tabpieces[$i]['sst_libelle'];
$strCmd .= "</td>\n";

}
$strCmd .="</table>";

echo $strCmd;
?>
0
kij_82 Messages postés 4088 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013 857 > kij_82 Messages postés 4088 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013
26 janv. 2007 à 14:08
Code corrigé :
//Affichage des pièces 
$strCmd="<br> 
<table class='boxtitle' width='100%' border='1' BORDERCOLOR='#000000' bgcolor='white' cellpadding='0' cellspacing='0'>\n"; 
If ($_SESSION['entreprise_active']!= 'BMA') 
{ 
$strCmd.="<tr>\n 
<td>PIECES INTERVENTION</td>\n 
<td><img src=\"../../images/changer.jpg\" height=\"22\" border=\"0\" onclick=\"popup_pieces('$numaffaire','$nomdo')\" alt=\"\" title=\"Gestion des pièces\" onmouseover=\"this.style.cursor='hand'\" width=\"22\" /></td> 
</tr>\n"; 
} 
$strCmd.=" <tr> \n 
<td width='1%' align='center'>Fournisseur</td>\n 
<td width='1%' align='center'>Référence</td>\n 
<td width='1%' align='center'>Désignation</td>\n 
<td width='1%' align='center'>Type Stock</td>\n 
<td width='1%' align='center'>Qté Cde</td>\n 
<td width='1%' align='center'><div id="Qte">Qté</div></td>\n 
<td width='1%' align='center'>Conso</td>\n 
<td width='1%' align='center'>Date Conso</td>\n 
<td width='1%' align='center'>N° Cde</td>\n 
<td width='1%' align='center'>Express</td>\n 
<td width='1%' align='center'>Date Cde</td>\n 
<td width='1%' align='center'>Date Liv</td>\n 
<td width='1%' align='center'>Agence Cde</td>\n 
</tr>\n"; 

for ($i=0;$i<$Nbpieces;$i++) 
{ 

$strCmd .= "<tr>"; 
$strCmd .= "<td align='center' class='affich'>\n"; 

if ($Tabpieces[$i]['sst_libelle'] == "STOCK CENTRAL") 
{ 
$strCmd .= "Call Center"; 
} 
else 
{ 
$strCmd .= Ucwords(strtolower($Tabpieces[$i]['nom_cf'])); 
} 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['reference']; 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['designation']; 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['sst_libelle']; 
$strCmd .= "</td>"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['qte_cdee']; 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['qte']; 
$strCmd .= "</td>\n"; 

$strCmd .= "<script language = 'Javascript'>"; 
$strCmd .= "function choix(bouton){"; 
$strCmd .= "if (bouton.checked)"; 
$strCmd .= "{"; 
$strCmd .= "if (bouton.value == "Oui" ){document.getElementById('Qte').value = 1;}"; 
$strCmd .= "else{document.getElementById('Qte').value = 0;}"; 
$strCmd .= "}"; 
$strCmd .= "}"; 
$strCmd .= "</script>"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= "<form >"; 
$strCmd .= "<input type='radio' name='choix_".$i."' value='Oui' onchange='choix(this)'> Oui<br>"; 
$strCmd .= "<input type='radio' name='choix_".$i."' value='Non' onchange='choix(this)'> Non<br>"; 
$strCmd .= "<input type='button' value='valider' name='valider($i)'onclick= 'choix($i)'>"; 
$strCmd .= "</form>"; 
$strCmd .= "</td>\n"; 

/*$strCmd .= "<script language = 'Javascript'>"; 
$strCmd .= "function choix(bouton){"; 
$strCmd .= "alert(bouton.value)"; 
$strCmd .= "}"; 
$strCmd .= "</script>"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= "<form name='formulaire_".$i."'>"; 
$strCmd .= "<input type='radio' name='choix_".$i."' value='Oui'> Oui<br>"; 
$strCmd .= "<input type='radio' name='choix_".$i."' value='Non'> Non<br>"; 
$strCmd .= "<input type='button' value='valider' name='valider_".$i."' onclick= 'choix(formulaire_".$i.".choix_".$i.")'>"; 
$strCmd .= "</form>"; 
$strCmd .= "</td>\n";*/ 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['datepieceenvoi']; 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['num_cde']; 
$strCmd .= "</td>\n"; 


$strCmd .= "<td align='center' class='affich'>\n"; 
if ($Tabpieces[$i]['express'] == 1) 
{ 
$strCmd .= "X"; 
} 
else 
{ 
$strCmd .= ""; 
} 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['datecde']; 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['datelivr']; 
$strCmd .= "</td>\n"; 

$strCmd .= "<td align='center' class='affich'>\n"; 
$strCmd .= $Tabpieces[$i]['sst_libelle']; 
$strCmd .= "</td>\n"; 

} 
$strCmd .="</table>"; 

echo $strCmd; 
?>


Je me permet de ré-itérer ma question, à quoi cela te sert-il de mettre le code de ta page dans une variable et de l'afficher ensuite ?
Ce ne serait pas plus clair et lisible de mettre directement le code ?
0
Mikius_92 Messages postés 35 Date d'inscription vendredi 26 janvier 2007 Statut Membre Dernière intervention 28 février 2007 > kij_82 Messages postés 4088 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013
26 janv. 2007 à 14:15
Ben en faite, c'était comme ca lorsque j'ai reprise le logiciel de ma boite et j'dois juste rajouter ou optimiser le code du logiciel donc bref je sais qu'ils auraient pu mettre le code directement mais bon d'aprés eux, c'est plus simple comme ca.

Et pour mon problème ?
0
kij_82 Messages postés 4088 Date d'inscription jeudi 7 avril 2005 Statut Contributeur Dernière intervention 30 septembre 2013 857
26 janv. 2007 à 14:35
Pense bien à mettre la balise "résolu" si la réponse te satisfait :)
0
Mikius_92 Messages postés 35 Date d'inscription vendredi 26 janvier 2007 Statut Membre Dernière intervention 28 février 2007
31 janv. 2007 à 09:22
ok merci je vais tester ce que tu as mis dans le dernier post ok désolé de répondre maintenant mais j'suis dans mon entreprise que 3 fois par semaine arf.
0