Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/11/2013, 12:50
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: Consulta en php

Código MySQL:
Ver original
  1. SELECT id_cliente,SUM(total)
  2. FROM cobros
  3. where fecha_cobro
  4.   BETWEEN ((select min(fecha_cobro) from cobros where estatusCobro = 0))
  5.  and DATE_ADD((select min(fecha_cobro) from cobros where estatusCobro = 0), INTERVAL 5 day)
  6. GROUP BY id_cliente;

Esto te dará lo que buscas....

Si necesitas el resto de campos llamados por *

Yo empezaria por agregar un order by id_cliente a la consulta y asi podrias en el bucle sumar sin peligro de liarte con otros clientes...

Código PHP:
Ver original
  1. if($accion == "cobros"){
  2.         $cobrosInicial = new query;
  3.         $cobrosInicial->validaquery("SELECT * from cobros where fecha_cobro
  4.                                BETWEEN ((select min(fecha_cobro) from cobros where estatusCobro = 0))
  5.                                and DATE_ADD((select min(fecha_cobro) from cobros where estatusCobro = 0), INTERVAL 5 day)
  6. ORDER BY id_cliente ");
  7.         if($cobrosInicial->cantidadreg() > 0){
  8.             $resultado2 = $cobrosInicial->devuelveresult();
  9.             $totFinal = 0;
  10.             $matrizTotales=array();
  11.             $idCliente=0;
  12.             $i=-1;
  13.             while($row2 = mysql_fetch_array($resultado2)){
  14.                 if($row2['id_cliente']!=$idCliente){
  15.                      $i++;
  16.                      $matrizTotales[$i]['id_cliente']=$row2['id_cliente'];
  17.                      $matrizTotales[$i]['total']=$row2['total'];
  18.                      $idCliente=$row2['id_cliente'];
  19.                 }else{
  20.                      $matrizTotales[$i]['total']+=$row2['total'];
  21.                  }
  22.             }
  23.         }
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.

Última edición por quimfv; 02/11/2013 a las 13:11