Using a MySQL result set with PHP
Posted: Mon Feb 20, 2006 6:19 am
Hello everyone,
i'm stuck on how to complete the following. Can any of you knowlegable programmers could help me out...
I select a bunch of records from a table:
r_id=0 r_year=2004 r_month=6 r_value=20
r_id=1 r_year=2004 r_month=8 r_value=10
r_id=2 r_year=2005 r_month=3 r_value=35
r_id=3 r_year=2006 r_month=1 r_value=18
These are end of month values, but i need the total from first record to now
My problem is that the missing months will have the same value as the last record
So the total will be... Tot=20+20+10+10+10+10+10+10+10+35+35...
(2004, 6) 20
(2004, 7) 20
(2004,
10
(2004, 9) 10
(2004,10) 10
(2004,11) 10
(2004,12) 10
(2005, 1) 10
(2005, 2) 10
(2005, 3) 35
(2005, 4) 35
(2005, 5) 35
etc...
Is this clear? i hope so.
Any help please
Jon
i'm stuck on how to complete the following. Can any of you knowlegable programmers could help me out...
I select a bunch of records from a table:
r_id=0 r_year=2004 r_month=6 r_value=20
r_id=1 r_year=2004 r_month=8 r_value=10
r_id=2 r_year=2005 r_month=3 r_value=35
r_id=3 r_year=2006 r_month=1 r_value=18
These are end of month values, but i need the total from first record to now
My problem is that the missing months will have the same value as the last record
So the total will be... Tot=20+20+10+10+10+10+10+10+10+35+35...
(2004, 6) 20
(2004, 7) 20
(2004,
(2004, 9) 10
(2004,10) 10
(2004,11) 10
(2004,12) 10
(2005, 1) 10
(2005, 2) 10
(2005, 3) 35
(2005, 4) 35
(2005, 5) 35
etc...
Is this clear? i hope so.
Code: Select all
$rH=mysql_query($qH, $conDB) or die(mysql_error()." Q=".$qH);
$rowsH=mysql_num_rows($rH);
// i've tried looping through the records, but its very difficult (for me)
$r=0; while ($rowH=mysql_fetch_assoc($rH)): extract($rowH);
if ($i=0): $tot=$r_value; endif;
if ($r>0): $tot=$tot+$r_value; endif; // i guess here i need some code to multiply the value by the number of months...aaahhhh....
$i=$i+1;
endwhile;Jon