E commerce Panier calculer le montant
Ginolattera
Messages postés
26
Statut
Membre
-
giztou Messages postés 7 Date d'inscription Statut Membre Dernière intervention -
giztou Messages postés 7 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
j'ai réalisé un panier de E com, j'ai de problème pour finir le calculer le montant total, il n'arrive pas faire l'addition des montants précédents, seulement afficher le montant partial, qq'un peut m'aider de modifier mon script ? svp!
<?php
session_start();
require_once 'panier.php';
$panier = new Panier('produits');
$listproduit = $panier->getPanier();
?>
<?php if(!$listproduit){?>
<p> votre panier est vide </p>
<?php } else {?>
<table border="1" width="50%">
<tr>
<td>Name</td>
<td>Price</td>
<td>Quantity</td>
<td>Montant</td>
</tr>
<?php foreach($listproduit as $produit) {
$totalprice=0;
$subtotal=$produit['quantity']*$produit['price'];
$totalprice+=$subtotal;
?>
<tr>
<td><?php print $produit['name'] ?></td>
<td><?php print $produit['price'] ?></td>
<td><?php print $produit['quantity'] ?></td>
<td><?php print($produit['quantity']*$produit['price'])?>€</td>
</tr>
<?php } ?>
<?php echo "Total: $totalprice";?>€
</table>
<?php } ?>
<p><a href="index.php">Accueil</a></p>
j'ai réalisé un panier de E com, j'ai de problème pour finir le calculer le montant total, il n'arrive pas faire l'addition des montants précédents, seulement afficher le montant partial, qq'un peut m'aider de modifier mon script ? svp!
<?php
session_start();
require_once 'panier.php';
$panier = new Panier('produits');
$listproduit = $panier->getPanier();
?>
<?php if(!$listproduit){?>
<p> votre panier est vide </p>
<?php } else {?>
<table border="1" width="50%">
<tr>
<td>Name</td>
<td>Price</td>
<td>Quantity</td>
<td>Montant</td>
</tr>
<?php foreach($listproduit as $produit) {
$totalprice=0;
$subtotal=$produit['quantity']*$produit['price'];
$totalprice+=$subtotal;
?>
<tr>
<td><?php print $produit['name'] ?></td>
<td><?php print $produit['price'] ?></td>
<td><?php print $produit['quantity'] ?></td>
<td><?php print($produit['quantity']*$produit['price'])?>€</td>
</tr>
<?php } ?>
<?php echo "Total: $totalprice";?>€
</table>
<?php } ?>
<p><a href="index.php">Accueil</a></p>
A voir également:
- E commerce Panier calculer le montant
- É majuscule - Guide
- Comment calculer la moyenne sur excel - Guide
- È majuscule - Forum Clavier
- Cdiscount mon panier ✓ - Forum Consommation & Internet
- E-plans - Télécharger - CAO-DAO
3 réponses
Bonjour,
C'est normal :
À chaque itération de la boucle, tu remets $totalprice à 0 !
Il faut inverser ces deux lignes.
Xavier
C'est normal :
<?php
foreach($listproduit as $produit) {
$totalprice=0;
À chaque itération de la boucle, tu remets $totalprice à 0 !
Il faut inverser ces deux lignes.
Xavier
giztou
Messages postés
7
Date d'inscription
Statut
Membre
Dernière intervention
merci Xavier.