$total=0; while (....) { //tu bucle while .... $total+ = $subtotal; // igual que $total=$total+$subtotal } // fin de tu bucle while echo $total;