php - How to total-up data in loop -
i have following data in html table:
all data in html table fecth using current query , html code:
$query=" select a.daily_budget ideal, c.lab_hour actual, b.store_name, b.storenum, c.busidate dummy_daily join site_store b on a.storenum = b.storenum join site_labour c on a.storenum = c.storenum (b.store_region='cr1') , (case when a.busidate between '2017-07-01' , '2017-07-05' a.daily_budget else 0 end) , (case when c.busidate between '2017-07-01' , '2017-07-05' c.lab_hour else 0 end) , (a.busidate = c.busidate)";
html code display in table:
$result2 = $dbhandle->query($query) or exit("error code ({$dbhandle->errno}): {$dbhandle->error}"); $no = 1; while ($row = mysqli_fetch_array($result2)) { $outlet= $row["store_name"]; $daily_ideal = $row["ideal"]; $code = $row['storenum']; $daily_actual=$row["actual"]; $test="test"; if($daily_ideal<3000) { $ideallabour=76.5; } else if($daily_ideal>=3000 && $daily_ideal<6000) { $ideallabour=106.5; } else if($daily_ideal>=6000 && $daily_ideal<9000) { $ideallabour=128; } else if($daily_ideal>=9000 && $daily_ideal<12000) { $ideallabour=152.5; } else if($daily_ideal>=12000 && $daily_ideal<15000) { $ideallabour=179.5; } else { $ideallabour=214; } if($daily_actual-$ideallabour>0) { $surplus=$daily_actual-$ideallabour; $shortage=0; } else { $shortage=$daily_actual-$ideallabour; $surplus=0; } echo "<tr class='y_n';>"; echo "<td><center>".$no."</center></td>"; echo "<td><center>".str_pad($code,3,"0", str_pad_left)."</center></td>"; echo "<td>".$outlet."</td>"; echo "<td>".$date1111."-".$date2111."</td>"; echo "<td>".$ideallabour."</td>"; echo "<td>".$daily_actual."</td>"; echo "<td>".$surplus."</td>"; echo "<td>".$shortage."</td>"; echo "</tr>"; $no++; }
my question is, how can total-up of "mtd ideal" , "mtd actual", , display within outlet.
this result of expected
no id outlet mtd ideal mtd actual +surplus -shortage 1 001 sunway putra mall 494 571 77 2 005 subang parade 426 508 82
this expected result should display in table.
the total mtd ideal , mtd actual sunway, subang total of mtd ideal , mtd actual in html table above.
please help
Comments
Post a Comment