Advertisement
cdsatrian

penjumlahan akumulatif dlm looping

Feb 7th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. //--
  2. echo "<table>";
  3. $sql="SELECT id,masuk,pulang,pulang-masuk AS selisih FROM tabel";
  4. $result=$db->query($sql);
  5. $total=0; //-- inisialisasi nilai total
  6. while($row=$result->fetch_object()){
  7.     echo "<tr><td>{$row->id}<td></td>{$row->masuk}<td></td>{$row->pulang}<td></td>{$row->selisih}</td></tr>";
  8.     $total+=$row->selisih; //-- lakukan akumulatif penjumlahan dalam loop, simpan hasilnya dalan variabel $total
  9. }
  10. echo "<tr><td></td><td></td><td>total jam/bulan<td></td>{$total}</td></tr>"; //-- tampilkan nilai $total, setelah semua looping dilakukan
  11. ?>
  12. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement