par
stefane321 » 03 janv. 2007, 22:35
Bonjour,
J'aimerais créer une boucle qui me créra des index de 1 à X et non de 0 à X
Comment faire?
Si j'utilise ça:
$nb_produits = 0;
$nb_produits = count($_SESSION["panier"]["id_produit"]);
for($y = 0; $y < $nb_produits; $y++)
{
echo "<input type=\"hidden\" name=\"item_name_".$y."\" value=\"".$_SESSION["panier"]["nom_produit"][$y]."\">\n";
echo "<input type=\"hidden\" name=\"item_number_".$y."\" value=\"".$_SESSION["panier"]["id_produit"][$y]."\">\n";
echo "<input type=\"hidden\" name=\"amount_".$y."\" value=\"".$_SESSION["panier"]["prix"][$y]."\">\n";
}
Sa commence à 0.
Si je met $y = 1 sa commence à 1 mais sa n'affiche pas le premier produit associé à l'index 1.
Pouvez-vous m'aider SVP?
Merci!
Bonjour,
J'aimerais créer une boucle qui me créra des index de 1 à X et non de 0 à X
Comment faire?
Si j'utilise ça:
[php]$nb_produits = 0;
$nb_produits = count($_SESSION["panier"]["id_produit"]);
for($y = 0; $y < $nb_produits; $y++)
{
echo "<input type=\"hidden\" name=\"item_name_".$y."\" value=\"".$_SESSION["panier"]["nom_produit"][$y]."\">\n";
echo "<input type=\"hidden\" name=\"item_number_".$y."\" value=\"".$_SESSION["panier"]["id_produit"][$y]."\">\n";
echo "<input type=\"hidden\" name=\"amount_".$y."\" value=\"".$_SESSION["panier"]["prix"][$y]."\">\n";
}[/php]
Sa commence à 0.
Si je met $y = 1 sa commence à 1 mais sa n'affiche pas le premier produit associé à l'index 1.
Pouvez-vous m'aider SVP?
Merci!