Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di polinet
    Registrato dal
    Nov 2000
    Messaggi
    993

    [PHP]Calcolare il totale

    Saranno state le cozze, ma ho un problema che non riesco a risolvere.
    Dovrei calcolare il totale "SPESA"
    Posto solo la parte interessata:
    Codice PHP:
    while ($rw=mysql_fetch_array($rs))
                     {
                         echo 
    "<td width=10% style=padding-left:10px>".$rw["id_prod"]."</td>";
                         echo 
    "<td width=40% style=padding-left:10px>".$rw["prodotto"]."</td>";
                         echo 
    "<td width=10% style=padding-left:10px>".$rw["pezzi"]."</td>";
                         echo 
    "<td width=20% style=padding-left:10px>".$rw["prezzo"]."</td>";
                         
    $totale number_format($rw["prezzo"] * $rw["pezzi"],2);
                         echo 
    "<td width=20% style=padding-left:10px>";
                         echo 
    $totale;
                         echo 
    "&euro;</td>";
                         echo 
    "</tr>";
                     }
                     echo 
    "</table>"
    Ora la variabile $totale mi calcola il totale per quel articolo.
    Ma per avere il TOTALE SPESA ????
    con un foreach?
    ¿Hasta la pasta?

  2. #2
    Utente di HTML.it L'avatar di zakros
    Registrato dal
    Oct 2000
    Messaggi
    509
    Se intendi il totale dei totali :



    $totali=0;
    while ($rw=mysql_fetch_array($rs))
    {
    echo "<td width=10% style=padding-left:10px>".$rw["id_prod"]."</td>";
    echo "<td width=40% style=padding-left:10px>".$rw["prodotto"]."</td>";
    echo "<td width=10% style=padding-left:10px>".$rw["pezzi"]."</td>";
    echo "<td width=20% style=padding-left:10px>".$rw["prezzo"]."</td>";
    $totale = number_format($rw["prezzo"] * $rw["pezzi"],2);
    echo "<td width=20% style=padding-left:10px>";
    echo $totale;
    echo "&euro;</td>";
    echo "</tr>";
    $totali+=$totale;
    }

    echo "<tr><td width=20% style=padding-left:10px>";
    echo $totali;
    echo "&euro;</td>";
    echo "</tr>";
    echo "</table>";

  3. #3
    Utente di HTML.it L'avatar di polinet
    Registrato dal
    Nov 2000
    Messaggi
    993
    Lo sapevo erano le cozze
    Grazie zakros.!!!

    ¿Hasta la pasta?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.