Hello hello,
Voilà, je rencontre un petit problème pour calculer la somme d'un tableau. C'est toujours pour mon script panier![]()
je fais avec un array_sum, mais cela me caclul que le dernier article passé dans le panier.
En fait je ne sais pas comment récuperer tout mes articles pour faire la calculation. Voici mon bout de code.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php //On contrôle si variable session panier est déclarée //Si c'est le cas on affiche les produits déclarés dans la session if(isset($_SESSION['panier'])) { ?> <!--PANIER <?php echo(join(",",array_keys($_SESSION['panier']))); ?>--> <table width="100%" cellpadding="5" cellspacing="0"> <?php //Si la session n'est pas vide on affiche le ou //les produits séléctionnés en faisant un foreach. //$session panier devient $produit foreach(array_keys($_SESSION['panier']) as $produit) { $info = produit_info($produit); // $total_prix = array($info['prix']); ?> <tr> <td> <div style="float:left;margin:0px"><?php echo($info['nom']); ?></div> <div style="float:right;margin:0px"><?php echo($info['prix']); ?> Frs</div> </td> </tr> <?php }//Fin du foreach ?> <tr> <td align="center"> <?php //Si la session panier est vide, on affiche "Panier vide" if (empty($_SESSION['panier'])) { ?>Panier vide<?php } //Sinon c'est que le panier contient au moins un produit else { ?> <div style="float:left;margin:0px">TOTAL:</div> <div style="float:right;margin:0px"><?php echo "".array_sum($total_prix)."" ;?> Frs</div> <br> <a href="valider.php">Valider le paiement</a> <?php }//Fin de la condition else ?> </td> </tr> </table> <?php }//Fin de la condition if $_SESSION['panier'] ?>
Partager