Query data mysql with x Days to win

2

I do not know what I'm doing wrong. in this code down was to show me the list of records with the dates that entered the house of the 3 days to win only that there are records that have already won

       $cmd = "SELECT f.*,a.* FROM a_finan AS f
       INNER JOIN agenda_saidas AS a
       ON a.id_saida = f.id_saida
       where a.id_transfer1 = '$id_transfer'  AND f.id_transfer =     
      '$id_transfer' AND f.status_servico = 'pend'
       **AND a.start <= DATE_ADD(now(),  INTERVAL 3 DAY)**         
       ";   

exe:hoje é **06-06-2015**
Tenho registros de 04-06-2015
                   05-06-2015
                   06-06-2015
                   07-06-2015
                   08-06-2015
                   09-06-2015 
a Consulta teria que me mostar só os dias 06 , 07 e 08  

Currently he is returning me until due dates 04 and 05. How could I solve this?

    
asked by anonymous 06.06.2015 / 16:55

1 answer

2

Use the Between clause in your query.

SELECT f.*,a.*
FROM a_finan AS f
INNER JOIN agenda_saidas AS a
ON a.id_saida = f.id_saida
WHERE a.id_transfer1 = '$id_transfer'
AND f.id_transfer = '$id_transfer'
AND f.status_servico = 'pend'
AND a.start BETWEEN NOW() AND DATE_ADD(NOW(),  INTERVAL 3 DAY);

Or

SELECT * 
FROM a_finan AS f
INNER JOIN agenda_saidas AS a USING(id_saida)
WHERE a.id_transfer1 = '$id_transfer'
AND f.id_transfer = '$id_transfer'
AND f.status_servico = 'pend'
AND a.start BETWEEN NOW() AND DATE_ADD(NOW(),  INTERVAL 3 DAY);

If the a.id_tranfer1 or f.id_transfer is a foreign key relationship then I do not see the need to WHERE a.id_transfer1 and AND f.id_transfer , just list one of the fields.

It may be that you have a conflict at the time of the search for the dates if the database field is only date and not datetime , in this case you only need to use DATE from mysql. DATE (NOW ()) ...

    
09.06.2015 / 05:00