I can't quite get a handle on whether or not my loop is creating bad data or my bad code is?
I have a series of loops that occur within one outer loop. The outer most loop simply loops through the number of months in the year starting with the current and goes backward to January.
Inside this loop are more loops that build arrays based on the month number of the outer loop. I won't show all of that code as it tends to be long and will require a lot of explanation. Basically inside the outer loop is a lot of math that is adding up totals of inventory for each month based on current levels, past orders and any adjustments made.
The first month (November) is the only month that is displaying the correct result. Each subsequent month is wrong. However, if I plug in the month number manually the result is correct. It seems like the outer loop itself is causing the final expected result to be incorrect for the months past November.
Is this a common thing or am I doing something wrong? Should I be resetting the loop in some way before it starts with the next month? Any help is appreciated.
This starts the outer loop to get things rolling. This starts with the current month and rolls back to January.
for($i = 0; $i < date('n'); $i++) {
$monthName = strtotime("today - $i months");
$monthId = date('m', $monthName);
If I hard code the month number I get the expected result for that month (11, 10, 09, 08 etc...). I can only get the one month at a time. I'd like to be able to display all the months in a single loop.
for($i = 0; $i < date('n'); $i++) {
$monthName = strtotime("today - $i months");
$monthId = 11;