Advertisement
Guest User

Untitled

a guest
May 28th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. <script>
  2. function startCalc(){
  3. interval = setInterval("calc()",1);}
  4. function calc(){
  5. one = document.autoSumForm.harga[].value;
  6. two = document.autoSumForm.jumlah[].value;
  7. document.autoSumForm.total.value = (one * two);}
  8. function stopCalc(){
  9. clearInterval(interval);}
  10. </script>
  11. <?php
  12. $ID = @$_GET['ID'];
  13. $sql_dokter = mysqli_query($koneksi,"SELECT * FROM tb_periksa_dokter WHERE id_periksa_dokter = '$ID'") or die (mysqli_error());
  14. $data_dokter = mysqli_fetch_array($sql_dokter);
  15. ?>
  16. <div class="row">
  17. <div class="col-lg-12">
  18. <h3 class="page-header"><i class="fa fa-file-text-o"></i> Data Obat</h3>
  19. <ol class="breadcrumb">
  20. <li><i class="fa fa-home"></i><a href="index.html">Home</a></li>
  21. <li><i class="icon_document_alt"></i>Data</li>
  22. <li><i class="fa fa-file-text-o"></i>Data Obat</li>
  23. </ol>
  24. </div>
  25. </div>
  26.  
  27. <div class="row">
  28. <div class="col-lg-12">
  29. <section class="panel">
  30. <header class="panel-heading">
  31. Data Obat
  32. </header>
  33. </div>
  34. <div class="panel-body">
  35. <div class="table-responsive">
  36. <form class="form-validate form-horizontal" id="feedback_form" method="POST" action="" name='autoSumForm'>
  37. <table id="datatables" class="table table-bordered table-hover table-striped">
  38. <thead>
  39. <tr>
  40. <th>No.</th>
  41. <th>Nama Obat</th>
  42. <th>Harga</th>
  43. <th>Jumlah</th>
  44. <th>Total</th>
  45. </tr>
  46. </thead>
  47. <tbody>
  48. <?php
  49.  
  50. include('../config/koneksi.php');
  51. $no = 1;
  52. $sql = "SELECT * FROM tb_obat";
  53. $query = mysqli_query($koneksi,$sql) or die (mysqli_error());
  54. $data = mysqli_fetch_array($query);
  55. //while($data = mysqli_fetch_array($query))
  56. //{
  57. ?>
  58. <tr>
  59. <td><?php echo $no++; ?></td>
  60. <td>
  61. <?php echo $data['nm_obat']; ?>
  62. <input type="hidden" name="id_periksa_dokter[]" value="<?php echo $data_dokter['id_periksa_dokter']; ?>" />
  63. <input type="hidden" name="id_obat[]" value="<?php echo $data['id_obat']; ?>" />
  64. </td>
  65. <td>
  66. <?php echo $data['harga']; ?>
  67. <input type="text" name="harga[]" onFocus="startCalc();" onBlur="stopCalc();" />
  68. </td>
  69. <td>
  70. <input type="number" name="jumlah[]" onFocus="startCalc();" onBlur="stopCalc();" />
  71. </td>
  72.  
  73. <?php
  74. //}
  75. ?>
  76.  
  77. <td>
  78. <input readonly type="number" name="total" readonly />
  79. </td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. <div class="form-group">
  84. <div class="col-lg-offset-5 col-lg-10">
  85. <input class="btn btn-primary" type="submit" value="Save" name="save">
  86. <button class="btn btn-default" type="reset">Cancel</button>
  87. </div>
  88. </div>
  89. </form>
  90. </div>
  91. </div>
  92. </section>
  93.  
  94. </div>
  95. </div>
  96.  
  97. <?php
  98. $id_periksa_dokter = @$_POST['id_periksa_dokter'];
  99. $id_obat = @$_POST['id_obat'];
  100. $jumlah = @$_POST['jumlah'];
  101. $harga = @$_POST['harga'];
  102. $hasil =
  103.  
  104. $save = @$_POST['save'];
  105.  
  106. if($save)
  107. {
  108. if($id_periksa_dokter == '' || $id_obat == '' || $harga == '' || $jumlah == '')
  109. {
  110. ?>
  111. <script type="text/javascript">alert("Inputan Tidak Boleh Kosong!")</script>
  112. <?php
  113. }
  114. else
  115. {
  116.  
  117. foreach ($jumlah as $i => $jumlah2)
  118. {
  119. if(!empty($jumlah2))
  120. {
  121. $sql_detail = "INSERT INTO tb_detail_obat VALUES ('$id_periksa_dokter[$i]', '$id_obat[$i]', '$harga[$i]', '$jumlah2')" or die (mysqli_error());
  122. $query = mysqli_query($koneksi,$sql_detail);
  123. }
  124. }
  125. echo "<script type='text/javascript'>alert('Tambah Data Berhasil');window.location.href='?page=periksa&action=selesai';</script>";
  126.  
  127. }
  128.  
  129. }
  130. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement