calcul prix total ht dans panier
Hors ligneVince22 Le 13/11/2005 à 22:45 Profil de Vince22 Configuration de Vince22

Bonjour, tout d'abord votre site est vraiment excellent, voici mon probleme je n'arrive pas à calculer le prix total HT dans un pannier voici le code session:
<?php session_start(); if (isset($_SESSION['panier']['nb_art'])) { // controle si un article existe deja dans le panier $id_art_sel=$_SESSION['panier']['nb_art']+1; // numero de l'article qui sera ajout } else {$id_art_sel=1;} // si il n'y a pas d'articles dj prsent echo '<form name="form1" method="post" action="http://www.informatiques-consommables.com/commandes/panier.php"> <INPUT type="hidden" name="id_art" value="'.$id_art_sel.'">'; // pour passage de l'id article ?>

code du panier:
<?php /* variables panier sous la forme : $_SESSION['panier'][ID article][array(ref=>blabla,designation=>blabla,prixht=>blabla,quantite=>blabla); */ session_start(); if (isset($_POST['id_art'])) { // si il s'agit de l'ajout d'un article     $_SESSION['panier'][$_POST['id_art']]['ref'] = $_POST['ref'];     $_SESSION['panier'][$_POST['id_art']]['designation'] = $_POST['designation'];     $_SESSION['panier'][$_POST['id_art']]['prixht'] = $_POST['prixht'];     $_SESSION['panier'][$_POST['id_art']]['quantite'] = $_POST['quantite']; } $nb_art=count($_SESSION['panier']); // nombre d'articles dans le panier if (count($_SESSION['panier']) > 0) { // si le panier n'est pas vide     echo'     <style type="text/css">     <!--     body,td,th {      color: #006699;     }     body {      background-image: url(../design/styles/fond.gif);     }     -->     </style>     <link href="../design/styles/styles.css" rel="stylesheet" type="text/css">     <table width="100%"  border="1" borderstyle="color: #FFFFFF" bgstyle="color: #FFFFFF">       <tr borderstyle="color: #BDDFE1" bgstyle="color: #BDDFE1" class="menugauche">         <td width="25%">Reference</td>         <td width="25%" borderstyle="color: #BDDFE1">Description</td>         <td width="25%">Prix HT &euro; </td>         <td width="25%">Quantit&eacute;</td>       </tr>     </table>';               // affichage du contenu du panier     for ($i=1;$i <= $nb_art; $i++) { // pour chaque article du panier         echo '<table width="100%" border="1" borderstyle="color: #FFFFFF" bgstyle="color: #FFFFFF" >           <tr>             <td width="25%">'.$_SESSION['panier'][$i]['ref'].'</td>             <td width="25%">'.$_SESSION['panier'][$i]['designation'].'</td>             <td width="25%">'.$_SESSION['panier'][$i]['prixht'].'</td>             <td width="25%">'.$_SESSION['panier'][$i]['quantite'].'</td>           </tr>         </table>';     } } else echo 'Votre panier ne contient aucun article.'; // le client n'a pas d'article dans son panier ?> <style type="text/css"> <!-- .Style2 {color: #006699; font-weight: bold; font-size: 12px; font-family: Geneva, Arial, Helvetica, sans-serif; } --> </style>     <p>&nbsp;</p>     <table width="100%" border="1" borderstyle="color: #FFFFFF" bgstyle="color: FFFFFF" >       <tr>         <td bgstyle="color: #FFFFFF"><a href="javascript:history.go(-1)" class="Style2">Poursuivre ma Commande</a></td>         <td bgstyle="color: #FFFFFF"><p align="right"><a href="Formulaire1.php" target="_self" class="Style2">Valider ma Commande</a></p>         </td>       </tr>     </table> <p>&nbsp;</p>

code du formulaire d'ajout d'articles:
PACK de 20 lecteurs de disquettes 3.5 PCE 1.44MB (coloris : beige) 0 1 2 3 4 5 6 7 8 9

url de demo:
http://www.informatiques-consommables.com/commandes/panier.php

en fait c le prix ht par la quantité qui me pose probleme,
merci
Hors ligneAnthony Le 13/11/2005 à 23:05 Profil de Anthony Configuration de Anthony

Admin
Salut,

tente un truc de ce genre :

<?php      $total=0;      while(list($cle,$valeur)=each($_SESSION['panier']))      {            if(is_numeric($cle))            {                    $total+=$valeur['prixht'];            }      }      echo $total; //prix total HT ?>
--

Hors ligneVince22 Le 13/11/2005 à 23:18 Profil de Vince22 Configuration de Vince22

merci je tente de suite...
Vous avez résolu votre problème avec VIC ? Faites-le savoir sur les réseaux sociaux !
Vulgarisation-informatique.com
Cours en informatique & tutoriels