1

I'm trying to create a rolling usage table where I iterate through 24 months of data using a MySQL query and then put the results into an array to be exported in a report, but I can't get the usage to properly get a running total. I'm adding my code below with my database information removed, but the report is working with just normal usages right now, just struggling with the rolling aspect of it.

//rolling usage table
//loop through 24 months of data 
for($i=0;$i<24;$i++){
    //Create indexes and dates for searching and storing.
    $epochTime = strtotime($myDate . "-$i months");
    $lastDay = date("t", $epochTime);
    $currentRollingMonthIndex = date("F Y", $epochTime);
    $endDate = date("Y-m-", $epochTime) . $lastDay;
    $beginDate = date("Y-m-01", $epochTime);

    //Collect the current month index.
    $rollingDates[$i] = $currentRollingMonthIndex;
    $rollingUsage = 0;

    //list all of the active products currently and their info
    $sql = "MY QUERY IS HERE";
    $res = $db->query($sql) or die($db->error()."<pre>$sql</pre>");

    //get the information from the db for each product
    while($row = $db->fetch_assoc($res)) {

    $id = isset($row['id']) ? $row['id'] : '';
      $usage = isset($row['usage']) ? $row['usage'] : '';

    $rollingUsageArr[$id][$currentRollingMonthIndex]['usage'] = $usage;
    }
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Tori
  • 75
  • 10

0 Answers0