I got this problem, my query is as follow:
$obtener_egresos_cobrados = mysql_query("SELECT SUM(subtotal) AS egresos_cobrados FROM rg_egresos WHERE id = '".$sesionidCont."' AND DATE_FORMAT(fecha, '%Y') = '".$primerFechaAnio."' AND DATE_FORMAT(fecha, '%m') < '".$primerFechaMes."' AND (tipoCuenta = 2 OR tipoCuenta = 3) AND (estado_factura = 1 OR estado_factura = 3) AND modificado = 0") or die (mysql_error());
$obtener_egresos_cobrados = mysql_fetch_assoc($obtener_egresos_cobrados);
$total_egresos_cobrados = $obtener_ingresos_cobrados['egresos_cobrados'];
And it suppose to return an amount of 10,000 but only returns null, and when I try to do this in phpMyAdmin directly this return the right amount, this is what phpMyAdmin generate after the query was executed:
SELECT SUM( subtotal ) AS egresos_cobrados
FROM rg_egresos
WHERE id =6
AND DATE_FORMAT( fecha, '%Y' ) = '2016'
AND DATE_FORMAT( fecha, '%m' ) < '02'
AND (
tipoCuenta =2
OR tipoCuenta =3
)
AND (
estado_factura =1
OR estado_factura =3
)
AND modificado =0
I tried to replace the variables $primerFechaAnio
and $primerFechaMes
with the values of the date but still not working, what I'm missing?