Ver Mensaje Individual
  #2 (permalink)  
Antiguo 25/04/2014, 08:37
Avatar de Eleazan
Eleazan
 
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años, 1 mes
Puntos: 326
Respuesta: Arrays - agrupar y sumar

Si lo haces con MySQL, puedes usar SUM y GROUP BY:

Código MySQL:
Ver original
  1. SELECT SUM(Pedidos.Cantidad) AS CantidadTotal FROM Pedidos GROUP BY Pedidos.Producto

Si lo quieres hacer con php, mientras recorres el array podrías hacer:
Código PHP:
while ( $tmp $sql->fetch() ) {
    if(
$array_final[$tmp["Producto"]]) $array_final[$tmp["Producto"]]+=$tmp['Cantidad'];
    else 
$array_final[$tmp["Producto"]] = $tmp['Cantidad'];

Y tendrías un array por producto / cantidad
__________________
>> Eleazan's Source
>> @Eleazan