and I also have two variables, $startmonth & $endmonth.
I want to achieve the following:
For each year (and the years are different for each id)
{
if between start & end month
{
sum totals
save total to a new array with only the year and it's total sum for selected months
}
}
Is this possible?
I'm stuck on scanning through the years (located at [0]). The years will range from 1920 to now. I know the logic, just not the commands. Any help?
foreach($dates as $date){
$curDate = $date[1].$date[0];
if(strlen($curDate) != 6)
$curDate = '0'.$curDate;
if($curDate > $startmonth && $curDate < $endmoneth){// excluding
//if($curDate >= $startmonth && $curDate <= $endmoneth){// including
// not sure what you want here, but this is a valid date.
// explain what things your summing etc and I'll help you out some more.
};
};
If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
The same applies to HTML and the forums [HTML][/HTML] tags.
As I said, I have two variables representing a starting month and an ending month. This should encompass a time period for the observation of values, of which I'd like to sum.
Say a start month of 6 and an end month of 9.
I then want to go through the array generated from an sqldb and sum up the values for month 6, 7, 8, and 9 for EACH year.
Right now I have an element for each month with the related year and value. IE: [2007][12][4.5] which is the year.month.value.
My first thought led me to think it'd be easier to first create an array for each year that held an array inside with a month => value relationship.
Ie 2006 2007
01 => 1's val 01 => 1's val
02 => 2's val 02 => 2's val
etc.
Then, I could go through each year and pick out the months I need and sum them up. From here I figure I can generate a final array that I can use to create a table and display a list of the highest values of the sum of the selected months.
My end goal is to have an array in this format:
For months (startmonth - endmonth):
(historic values)
2007 => Val
2006 => Val
2005 => Val
Which I can then compare against the forecasted value and generate a table of the current years value relative to historic years.
Actually, it looks like it's working, but I just need to find a way to deal with nulls (set to -9999) that are mucking things up. A different source generated this output:
But what if I only want to display the current years rank and maybe 3 or 4 above and below the current years rank, plus the top one?
I'd image I'd scan through, look for the rank of the current year, save it, then do display my table with +/- a value of the current years rank and just display that. I can do this simple enough, but I was curious if there was a way an expert would approach this with less work?
Bookmarks