membuat perhitungan pada tabel array

herpendi · May 28, 2018
Selamat sore agan2, mohon pencerahannya.
Saya membuat membuat perhitungan rata2 pada tabel array, pada row pertama berhasil menghitung namun pada row berikutnya gagal. mohon bantuannya, terima kasih agan2...

https://img1.uploadhouse.com/fileuploads/26092/260925516e556090107abe660965bdcf9160283e.jpg

<script language="javascript" >
function OperasiPerhitungan(){
A1 = document.getElementById("angka1").value;
A2 = document.getElementById("angka2").value;
A3 = (parseFloat(A1) + parseFloat(A2))/2;
document.getElementById("hasil").value =A3;
}
</script>
	<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">
		<div class="row">
			<div class="col-lg-12">
				<center><h3 class="page-header">EDIT NILAI</h3></center>
			</div>
		</div><!--/.row-->	
        <?php include ('koneksi.php');
        $nip=$_SESSION['$nip'];
        ?>
<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-danger">
					<div class="panel-body">
					<form method="POST" action="input_nilai_edit_proses.php">
						<table id="example" class="" cellspacing="0" width="100%">
						        <thead>
						            <tr class="alert warning">
						            	<th>No</th>
						            	<th></th>
						            	<th>NIS</th>
						            	<th>Siswa</th>
						            	<th>UH 1</th>
						            	<th>UH 2</th>
								<th>RERATA</th>
						            </tr>
						        </thead>						
						        <tbody>
								<?php
								include('koneksi.php');
								$id_mapel = $_GET['id_mapel'];
								$query = mysql_query("SELECT siswa.nama,nilai.id_mapel, nilai.id_nilai, 
								nilai.nis, nilai.uh1,nilai.uh2
								FROM siswa, nilai WHERE siswa.nis=nilai.nis AND nilai.id_mapel= '$id_mapel'");
								 $no = 0;	//membuat variabel $no untuk membuat nomor urut
								while($data = mysql_fetch_array($query)){
								 $no++;
								 $id_nilai = $data['id_nilai'];
								$id_mapel = $data['id_mapel'];
								$rerata = $data['rerata'];
								?>
				<tr>
				<td><?php echo $no; ?></td>
				<td><input type="hidden" name="id_nilai[]" value="<?php echo $data['id_nilai']; ?>"></td>
				<td><?php echo $data['nis']; ?></td>
				<td><?php echo $data['nama']; ?></td>
				<td><input type="number" name="uh1[]" id="angka1" onchange="OperasiPerhitungan();" value="0" style="width:50px"></td>
				<td><input type="number" name="uh2[]" id="angka2" onchange="OperasiPerhitungan();" value="0" style="width:50px"></td>
				<td><input type="number" name="rerata[]" id="hasil" disabled="disabled" value="0" style="width:80px"></td>
				</tr>
						            <?php } ?>
						    	</tbody>
						    </table>
							<div class='navbar-form pull-left'>
							<button type="submit" name="tambah" class="btn btn-danger">Simpan</button>
							</div>
						</form> 
Silahkan login untuk menjawab!