Ver Mensaje Individual
  #6 (permalink)  
Antiguo 01/02/2011, 15:58
Avatar de mko
mko
 
Fecha de Ingreso: agosto-2010
Ubicación: la vida es un riesgo
Mensajes: 101
Antigüedad: 13 años, 8 meses
Puntos: 14
Respuesta: Crear funcion que sume todos los campos por ID [Asesoramiento]

bien, creo que ya te agarre la onda quiere sumar a final de la consulta el total neto de todos los subtotales si estoy en lo correcto es asi si no pos no entendi la la onda
:::::::::::::::::::::::::::::::::::::::

esto la cantidad total de ventas en base a una fecha de busqueda...modifica segun tu necesidad

aqui tu conoccion....



$registros=mysql_query("select compania,distribuidor,pieza,precio,can,fecha from VENTA WHERE fecha='$[fecha]'") or
die("Error de conexion");

if ($row = mysql_fetch_array($registros)){
$to=0;
echo "<table border='1'>";
echo "VENTAS DEL MES DE:<font size= '5' color='blue'>".$row["fecha"]."</font>";
echo "<tr>";
echo "<td><font size='2' color='black'>DISTRIBUIDOR</font></td>
<td><font size='2' color='black'>CVE_SEGURO</font></td>
<td><font size='2' color='black'>PIEZA</font></td>
<td><font size='2' color='black'>PRECIO</font></td>
<td><font size='2' color='black'>CAN</font></td>
<td><font size='2' color='black'>SUBTOTAL</font></td>";
echo "</tr>";
do {

echo "<tr>";
echo "<td><font size= '4' color='blue'>".$row["distribuidor"]."</font></td>
<td><font size= '4' color='blue'>".$row["compania"]."</font></td>
<td><font size= '4' color='blue'>".$row["pieza"]."</font></td>
<td><font size= '4' color='blue'>".$row["precio"]."</font></td>
<td><font size= '4' color='blue'>".$row["can"]."</font></td>
<td><font size= '4' color='blue'>".$sub=$row["precio"]*$row["can"]."</font></td>";
echo "</tr>";
$total += $sub;

} while ($row = mssql_fetch_array($registros));

echo "<tr>";
echo "<td><font size= '4' color='red'></font></td>
<td><font size= '4' color='red'></font></td>
<td><font size= '4' color='red'></font></td>
<td><font size= '4' color='red'></font></td>
<td><font size= '4' color='red'>TOTAL:</font></td>
<td><div align='right'><font size= '4' color='006600'>".$total."</font></div></td>
<td><font size= '4' color='blue'></font></td>";
echo "</tr>";

echo "</table> \n";
}






si te das cuanta

$total += $sub; lo que hace es acumular todos los subtotales


espero sea lo que buscabas