Help....Simpan data array...!!!!

ant · Sep 17, 2012
Selamat siang Mas Ellyx, saya mohon pencerahannya ni?
Saya punya cuplikan script seperti dibawah ini:
<script language="JavaScript" src="jquery.js"></script>
<script>
	
	function addTableRow(jQtable){
		jQtable.each(function(){
			var $table = $(this);
			var n = parseInt(document.getElementById('nomor').value) + 1;
			var brg = document.getElementById('barang').value;
			var qty = document.getElementById('qty').value;
			var harga_beli = document.getElementById('harga_beli').value;
			if ((qty<=0) || (harga_beli<=0)) {
				alert('QTY dan HARGA tidak boleh kosong atau minus');
			}
			else {
				var brgs= brg.split('-');
				var tds = '<tr>';
				tds += '<td align=center>'+brgs[1]+'<input type="hidden" name="brg['+n+']" value="'+brgs[0]+'" /></td>';
				tds += '<td>'+brgs[2]+'</td>';
				tds += '<td align=center>'+qty+'<input type="hidden" name="qty['+n+']" id="qty['+n+']" value="'+qty+'" /></td>';
				tds += '<td align=center>'+harga_beli+'<input type="hidden" name="harga_beli['+n+']" id="harga_beli['+n+']" value="'+harga_beli+'" /></td>';
				tds += '<td align=center class="delete" onClick="$(this).parent().remove(); minTotal('+qty+'); minHarga('+harga_beli+') "><a href="javascript:void(0)">Hapus</a></td>';
				tds += '</tr>';
				if($('tbody', this).length > 0){
					$('tbody', this).append(tds);
				}else {
					$(this).append(tds);
				}
				document.getElementById('nomor').value =  n;
			}
		});
	}

	function hitTotal() {
		var no = parseInt(document.getElementById('nomor').value);
		var tQty = parseInt(document.getElementById('total').innerHTML);
		var lastQty = parseInt(document.getElementById('qty['+no+']').value);
		tQty += lastQty;
		document.getElementById('total').innerHTML = tQty;
	}
	
	function hitHarga() {
		var no = parseInt(document.getElementById('nomor').value);
		var tHrg = parseInt(document.getElementById('total_harga').innerHTML);
		var lastHrg = parseInt(document.getElementById('harga_beli['+no+']').value);
		tHrg += lastHrg;
		document.getElementById('total_harga').innerHTML = tHrg;
	}

	function minTotal(qty) {
		var tQty = parseInt(document.getElementById('total').innerHTML);
		tQty -= parseInt(qty);
		document.getElementById('total').innerHTML = tQty;
	}
	
	function minHarga(harga_beli) {
		var tHrg = parseInt(document.getElementById('total_harga').innerHTML);
		tHrg -= parseInt(harga_beli);
		document.getElementById('total_harga').innerHTML = tHrg;
	}
	
	function deleteAllRows() {
		$('#myTable tbody').remove();
		document.getElementById('total').innerHTML = 0;
		document.getElementById('total_harga').innerHTML = 0;
	}
	
</script>

Ini Inputan arraynya mas:
<tr>
		<td> Nama Barang </td>
		<td> : </td>
		<td>
			<select name='barang' id="barang" class='inputbox'><option value=''>[ Pilih Barang ]</option>
				<?php
					$q = mysql_query("SELECT * FROM barang");
					while($d = mysql_fetch_array($q)) {
						echo "<option value='".$d[0]."-".$d[1]."-".$d[2]."'>".$d[1]." | ".$d[2]."</option>";
					}
				?>
				
			</select> 
			QTY <input type='text' class="yellowBGField" name='qty' id='qty' size='2' > 
			Harga Total <input type='text' class="yellowBGField" name='harga_beli' id='harga_beli' size='10' > 
			<input type="button" name="tambah" value=" Tambahkan " id="tambah" onClick="addTableRow($('#myTable')); hitTotal();hitHarga();" />
			<input type='hidden' name='nomor' id='nomor' value='0' >
		</td>
	</tr>
Masalahnya ada di sini mas:
if($r1) {
				$adaID = mysql_result(mysql_query("SELECT ada_id FROM pengadaan WHERE ada_nota = '".$nota."'"),0,0);
				if($_POST['brg']!='') {
					$brg = $_POST['brg']; 
					foreach ($_POST['qty'] as $key => $val) {
						$q2 = "INSERT INTO detail_pengadaan VALUES (null,'".$val."','".$brg[$key]."', '".$adaID."')";
						$r2 = mysql_query($q2);
					}
				}
			}
Nah dikode diatas hanya menyimpan QTY.....Tappi untuk menyimpan HARGA BELI nya bagaimana ya mas?
Terimakasih....
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Sep 17, 2012 · 0 Suka · 0 Tidak Suka
sedikit susah yang memberi tahunya, ini trik yang sering saya lakukan ketika kesusahan memproses data.
tambahkan tiga baris berikut untuk mengetahui struktur data yang kita sedang proses.
echo '<pre>';
var_dump($_POST);
echo '</pre>';
0
Loading...
ant · Sep 18, 2012 · 0 Suka · 0 Tidak Suka
Terimakasih Mas Ellyx, Problem Solved !:)