Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/06/2010, 23:08
Avatar de truman_truman
truman_truman
 
Fecha de Ingreso: febrero-2010
Ubicación: /home/user
Mensajes: 1.341
Antigüedad: 14 años, 3 meses
Puntos: 177
Pregunta Sumar valores en un WHILE

Hola quiero saber como sumar los subtotales obtenidos en un WHILE , dejo el cogido simplificado:


Código PHP:
while ($fila1=mysql_fetch_array($consulta1)){ 

$consulta2=mysql_query("SELECT * FROM productos WHERE id ='".$fila1['id_producto']."'",$conexion);

$fila2=mysql_fetch_array($consulta2);


// ESTOS SON LOS SUBTOTALES QUE QUIERO SUMAR

$sub_total=$fila1['cantidad']*$fila2['precio_producto'];

// ES DECIR, EN CADA VUELTA "$sub_total" TENDRÁ UN VALOR DISTINTO
// Y YO , QUIERO SUMAR ESOS VALORES PARA OBTENER UN RESULTADO TOTAL COMO HAGO????