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
| <?php
if (isset($_POST['choix'],$_POST['tab_produit']))
foreach ($_POST['choix'] as $id_produit)
{
if (isset($_POST['tab_produit'][$id_produit]))
foreach ($_POST['tab_produit'][$id_produit] as $key => $value)
{
echo $key. ' = ' .$value.'<br>';
}
echo '-------------------<br>';
}
//Correspond à des lignes récupérées en bdd
$tab_test = array();
$tab_test['ligne1']['id'] = 'id_1';
$tab_test['ligne1']['nom'] = 'nom_1';
$tab_test['ligne1']['prix'] = 'prix_1';
$tab_test['ligne2']['id'] = 'id_2';
$tab_test['ligne2']['nom'] = 'nom_2';
$tab_test['ligne2']['prix'] = 'prix_2';
$tab_test['ligne3']['id'] = 'id_3';
$tab_test['ligne3']['nom'] = 'nom_3';
$tab_test['ligne3']['prix'] = 'prix_3';
?>
<form action="#" method="post">
<?php foreach ($tab_test as $value)
{ ?>
<input type = "hidden" name = "tab_produit[<?=$value['id']?>][nom]" value = "<?= $value['nom'] ?>" />
<input type = "hidden" name = "tab_produit[<?=$value['id']?>][prix]" value = "<?= $value['prix'] ?>" />
<?= $value['nom'] ?> <?= $value['prix'] ?> <input type="checkbox" name = "choix[]" value = "<?=$value['id']?>" /><br />
<?php } ?>
<input type = "submit" name = "envoyer" value = "envoyer" />
</form> |