Ver Mensaje Individual
  #18 (permalink)  
Antiguo 23/08/2010, 12:05
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: tomar el último valor de array

No es necesario hacer dos consultas:
Código PHP:
Ver original
  1. $consulta = "SELECT tipo, sum(valor), COUNT(unidades) FROM miTabla GROUP BY tipo;";
  2. $resultado = mysql_query($consulta) or die (mysql_error());
  3. $total = array();
  4. while ($col = mysql_fetch_array($resultado, MYSQL_NUM)) {
  5.           $suma = $col[1];
  6.           $conteo = $col[2];
  7.  
  8.           $thisTotal = ($suma / $conteo);
  9.           echo $thisTotal . "<br />";
  10.           $total[] = $thisTotal;
  11. }
  12. echo array_sum($total);

Saludos.