Forum Moderators: coopster

Message Too Old, No Replies

print all entries mysql together

         

helenp

7:12 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi I have above selects, and to view by property I normally use WHERE propiedades.id_propiedad = '$propiedad'
it works just perfect,

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);

helenp

10:56 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



nobody...
maybe didnīt explain well,
how to display all entries in an table using one query, but display them separate ordered by id, and then mix it with selct 2 and 3?
must be some way.

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.

freeflight2

2:41 am on Nov 11, 2004 (gmt 0)

10+ Year Member



not sure exactly what your query is doing to be honest but did your try to use the GROUP BY statement

helenp

10:05 am on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



yes thanks, finally I did it with the GROUP by statements for the sum selects,
and order by for the first select,
thats OK, even though wasnt wat i tried to do.

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,