Advertisement
Guest User

Untitled

a guest
May 5th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. // $array = array(
  4. // 'a' => array('id_mesin' => 'mesin1', 'berat' => '1'),
  5. // 'b' => array('id_mesin' => 'mesin2', 'berat' => '2'),
  6. // 'c' => array('id_mesin' => 'mesin3', 'berat' => '3'),
  7. // 'd' => array('id_mesin' => 'mesin4', 'berat' => '4'),
  8. // 'e' => array('id_mesin' => 'mesin5', 'berat' => '5'),
  9. // 'f' => array('id_mesin' => 'mesin6', 'berat' => '6'),
  10. // 'g' => array('id_mesin' => 'mesin7', 'berat' => '7'),
  11. // 'h' => array('id_mesin' => 'mesin8', 'berat' => '8'),
  12. // 'i' => array('id_mesin' => 'mesin9', 'berat' => '9'),
  13. // 'j' => array('id_mesin' => 'mesin10', 'berat' => '10'),
  14. // 'k' => array('id_mesin' => 'mesin11', 'berat' => '11'),
  15. // 'l' => array('id_mesin' => 'mesin12', 'berat' => '12')
  16. // );
  17.  
  18. $koneksidb = mysql_connect("localhost","root","");
  19. $con = mysql_select_db("latihan",$koneksidb);
  20. if(!$con)
  21. {
  22. echo "Koneksi GAGAL ke Penjualan or Server Down Hub. Admin!";
  23. }
  24.  
  25. echo $query = "SELECT tgl, id_mesin, brt_nyata, akm_mesin
  26. FROM harian
  27. WHERE tgl = '2015-04-01'
  28. ORDER BY id_mesin, tgl ASC";
  29. $hasil = mysql_query($query);
  30. $array = mysql_fetch_assoc($hasil);
  31.  
  32. echo '<table border="1">';
  33. //set akm ke default yaitu nol
  34. $akm = 0;
  35. foreach ($array as $value) {
  36. echo '<tr>';
  37. echo '<td>';
  38. echo $value['id_mesin'];
  39. echo '</td>';
  40. echo '<td>';
  41. echo $value['berat'];
  42. echo '</td>';
  43. echo '<td>';
  44. // akm adalah akm sebelumnya ditambah berat
  45. $akm = $akm + $value['berat'];
  46. echo $akm;
  47. echo '</td>';
  48. echo '</tr>';
  49. }
  50. echo '</table>';
  51.  
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement