Ver Mensaje Individual
  #3 (permalink)  
Antiguo 15/02/2017, 13:36
elsaiya
 
Fecha de Ingreso: marzo-2012
Ubicación: El Vigia Edo Merida
Mensajes: 147
Antigüedad: 12 años, 11 meses
Puntos: 1
Respuesta: Como mostrar la cantidad de prestamos por meses

amigo muchas gracias por responder, la verdad logre mostrar lo que queria de esta manera, no se si seria un consulta muy barbara, me refiere a q me podria dar error en algun futuro


Código PHP:
Ver original
  1. public function LibrosPExternos()
  2.     {
  3. $year = date('Y');
  4. $tipo = 'EXTERNO';
  5. $sql = "select
  6. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='01' AND tipoprestamo = '".$tipo."') as enero,
  7. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='02' AND tipoprestamo = '".$tipo."') as febrero,
  8. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='03' AND tipoprestamo = '".$tipo."') as marzo,
  9. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='04' AND tipoprestamo = '".$tipo."') as abril,
  10. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='05' AND tipoprestamo = '".$tipo."') as mayo,
  11. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='06' AND tipoprestamo = '".$tipo."') as junio,
  12. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='07' AND tipoprestamo = '".$tipo."') as julio,
  13. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='08' AND tipoprestamo = '".$tipo."') as agosto,
  14. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='09' AND tipoprestamo = '".$tipo."') as septiembre,
  15. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='10' AND tipoprestamo = '".$tipo."') as octubre,
  16. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='11' AND tipoprestamo = '".$tipo."') as noviembre,
  17. (select count(*) from prestamos where YEAR(fechaprestamo) = '".$year."' AND MONTH(fechaprestamo) ='12' AND tipoprestamo = '".$tipo."') as diciembre";
  18.  
  19.         foreach ($this->dbh->query($sql) as $row)
  20.         {
  21.             $this->p[] = $row;
  22.         }
  23.         return $this->p;
  24.         $this->dbh=null;
  25.     }