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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<?php require('connexion.php'); ?>
<?php
$cookie_achat = $_GET['id']; //recuperation de la variable externe
if (!isset($_COOKIE['panier']))// si le cookie n'est pas renseigné
{
echo "à creer si le cookie n'existe pas";
$tableau_panier[]= $cookie_achat;// création du tableau "$tableau_panier" sous forme de variable avec la valeur de $cookie_achat
$tab_panier = serialize($tableau_panier) ; //serialisation du tableau sous
setcookie ('panier', $tab_panier, time()+1296000);// le cookie "panier" prend la valeur $tab_panier, durée de vie 15 Jours 1296000)-->
}
else
{
echo "le cookie existe deja";
$tableau_panier = unserialize($_COOKIE['panier']); // deserialisation du tablea
$tableau_panier[] = $cookie_achat; //ajout des nouvelles donées au anciennes dans le cookie
$tab_panier = serialize($tableau_panier) ; //serialisation du tableau sous
setcookie ('panier', $tab_panier, time()+1296000);// le cookie "panier" prend la valeur $tab_panier, durée de vie 15 Jours 1296000)-->
}
foreach ($tableau_panier as $articles)
{
// Récupération des éléments nom et prix par filtrage sur l'ID
$result = $mysqli->query('SELECT produit_id, produit_nom, prix FROM produits WHERE produit_id = '. $articles);
while ($row = $result->fetch_array())
$produits[$row['prix']] = $row['produit_nom'];//affiche qu'une fois
}
$total_amount = 0; // initialisation de la variable de calcule
foreach ($produits as $prix => $select_nom):
$total_amount += $prix; // addition du prix coréspondant
?>
<!-- Récupération des informations et affichage -->
<table border="1">
<tr>
<td width='180px' align=center>nom du produit</td>
<?php echo"<td width='180px' align=center>".$select_nom."</td>"; ?>
<td width='80px' align=center>prix en </td>
<?php echo"<td width='80px' align=center>".$prix."</td>";?>
</tr>
</table>
<p>
<h3>Le montant total était de <?php echo $total_amount; ?> </h3>
</p>
</div>
<?php endforeach ?> |
Partager