Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/11/2012, 15:24
f4b14n
 
Fecha de Ingreso: agosto-2006
Mensajes: 24
Antigüedad: 17 años, 8 meses
Puntos: 9
Respuesta: Agrupar registros

Prueba usando esto

Código PHP:
Ver original
  1. <?php
  2. $link = mysql_connect("localhost", "root", "");
  3. mysql_select_db("pruebas", $link);
  4.  
  5. $items = array( "n1" => "Muy Bajo",
  6.                 "n2" => "Bajo",
  7.                 "n34" => "Moderado",
  8.                 "n5" => "Alto");
  9.  
  10. $sql = "SELECT
  11.         (SELECT count(*) AS cant  FROM  t_motivo as tmp  WHERE puntuacion = 1) AS n1,
  12.         (SELECT count(*) AS cant  FROM  t_motivo as tmp  WHERE puntuacion = 2) AS n2,
  13.         (SELECT count(*) AS cant  FROM  t_motivo as tmp  WHERE (puntuacion = 3 OR puntuacion = 4)) AS n34,
  14.         (SELECT count(*) AS cant  FROM  t_motivo as tmp  WHERE puntuacion >= 5) AS n5
  15.         FROM t_motivo
  16.         LIMIT 0,1";
  17.        
  18. $result_p=mysql_query($sql, $link) or die (mysql_error());
  19. $row = mysql_fetch_array($result_p);
  20.  
  21. foreach ($items as $key => $puntuacion)
  22. {
  23.     echo "[$puntuacion - Total: {$row[$key]}]<br / >";
  24. }
  25.  
  26. ?>