Forum Moderators: coopster
but I would like to be able to view all '$propiedad' in one select that will group them by id_propiedad with their balances, to print it out once a month.
So I tried to change it to just WHERE propiedades.id_propiedad = propiedades.id_propiedad
How can this be done with above selects?
$result = mysql_query("SELECT propiedades.id, bla, bla WHERE propiedades.id_propiedad = propiedades.id_propiedad and month(fecha) = '$month' and year(fecha) = '$year' order by fecha", $dbh);
if ($row = mysql_fetch_array($result)){
$result=mysql_query("select
sum(importe)
- sum(servicios)
-sum(pagado) as total_duenos
from propiedades where fecha <= DATE_ADD('$date', INTERVAL -1 MONTH) and propiedades.id_propiedad = propiedades.id_propiedad",$dbh);
$result=mysql_query("select sum(
case when month(fecha) = '$month' and year(fecha) = '$year' and propiedades.id_propiedad = propiedades.id_propiedad
then importe
else null end
) as sum_importe_this_month
, sum(
case when month(fecha) = '$month' and year(fecha) = '$year' and propiedades.id_propiedad = propiedades.id_propiedad
then servicios
else null end
) as sum_servicios_this_month
, sum(
case when month(fecha) = '$month' and year(fecha) = '$year' and propiedades.id_propiedad = propiedades.id_propiedad
then pagado
else null end
) as sum_pagado_this_month
, sum(importe)
- sum(servicios)
-sum(pagado) as total_duenos
from propiedades where fecha <= '$date' and propiedades.id_propiedad = propiedades.id_propiedad",$dbh);
Like this:
property1 date1 from table1, select 1
balances from table2, select2
property2 date 1 from table 1, select 1
balances from table2, select 2
sort of making the querys and fetch array repeating until everything is displayed.
Now I have 3 results for the 3 diferents select, thats ok, but I wanted to mix the 3 selects as an union, but union wonīt work though the selects are totally diferents.
I wanted to do the 3 selects first for id 1, then automatically for id 2 and so on, not doing the selects for all ids at the same time.
Thanks,