update 2 table dengan multi row

Hanamichi Sakuraghi · Aug 3, 2012
ak pny 2 table bbk dan bbk detail


CREATE TABLE IF NOT EXISTS `t_bbk` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`bbk_number` varchar(30) NOT NULL,
`so_number` varchar(30) NOT NULL,
`order_number` varchar(30) NOT NULL,
`order_tgl` date NOT NULL,
`tgl` date NOT NULL,
`gudang` varchar(30) NOT NULL,
`kategori` varchar(15) NOT NULL,
`notes` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


CREATE TABLE IF NOT EXISTS `t_bbkdetail` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`id_bbk` int(5) NOT NULL,
`nama_brg` varchar(30) NOT NULL,
`spl` varchar(10) NOT NULL,
`code` varchar(20) NOT NULL,
`speck1` varchar(10) NOT NULL,
`speck2` varchar(10) NOT NULL,
`speck3` varchar(10) NOT NULL,
`qty` int(5) NOT NULL,
`satuan` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
editbbkForm.php

<form method="post" action="updateBbk.php">
        <input type="hidden" name="id" value="<?php echo"$id"; ?>">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
	<td width="11">&nbsp;</td>
    <td width="876" valign="top">
			<table width="100%" border="0" cellspacing="0" cellpadding="1">
					<tr>
					  <th colspan="6" align="left"><span class="style8">VIARA Plastics</span></th>
					  <th align="left">&nbsp;</th>
					  <th align="center">&nbsp;</th>
					  <th colspan="3" align="left">&nbsp;</th>
					  <th align="left">&nbsp;</th>
				  </tr>
					<tr>
					  <th colspan="6" align="left">Bukti Barang Keluar</th>
					  <th align="left">&nbsp;</th>
					  <th align="center">&nbsp;</th>
					  <th colspan="3" align="left">&nbsp;</th>
					  <th width="146" align="left">&nbsp;</th>
				  </tr>
					<tr>
						<th width="178" align="left"> BBK No</th>

					  <th width="26" align="center">:</th>
					  <td colspan="4" align="left"><input type="text" name="bbk_number" value="<?php echo $bbk_number?>" /></td>
					  <th width="50" align="left">&nbsp;</th>
					  <th width="27" align="center">&nbsp;</th>
				      <th width="174" align="left">Tanggal</th>
				      <td colspan="3" align="left"> : &nbsp;&nbsp;&nbsp;<?php echo $tgl; ?></td>
			      </tr>
					<tr>
					  <th align="left">Sales Order No</th>
					  <th align="center">:</th>
					  <td colspan="4" align="left"><input type="text" name="so_number" value="<?php echo $so_number?>" /></td>
					  <th align="left">&nbsp;</th>
					  <th align="center">&nbsp;</th>
					  <th width="174" align="left">Gudang</th>
				      <td colspan="3" align="left"> : &nbsp;&nbsp;&nbsp;<input type="text" name="gudang" value="<?php echo $gudang; ?>" size="15" /></td>
			      </tr>
					<tr>
						<th align="left">Order Produksi No</th>
						<th align="center">:</th>
						<td colspan="4" align="left"><input type="text" name="order_number" value="<?php echo $order_number?>" /></td>
						<th align="left">&nbsp;</th>

						<th align="center">&nbsp;</th>
					  <th width="174" align="left">Kategori</th>
	        <td colspan="3" align="left">: &nbsp;&nbsp;&nbsp;<select name="kategori" id="<?php echo $kategori?>">
                          <option id="Bahan Baku">Bahan Baku</option>
                          <option id="Produk Jadi">Produk Jadi</option>
                      </select></td>
				  </tr>
					<tr>
					  <th align="left">Tanggal Order</th>
					  <th align="center">:</th>
					  <td colspan="4" align="left"><input type="text" name="order_tgl" id="demo3" maxlength="25" size="25" class="text_box" value="<?php echo $order_tgl?>"/>
          <a href="javascript:NewCssCal('demo3','yyyymmdd')"> <img src="images/cal.gif" width="16" height="16" alt="Pick a date" /></a>&nbsp;</td>
					  <th align="left">&nbsp;</th>
					  <th align="center">&nbsp;</th>
					  <th align="left">&nbsp;</th>
					  <td colspan="3" align="left">&nbsp;</td>
				  </tr>
				</table>
			    <table width="100%" border="1" cellspacing="0" cellpadding="0" class='tab' id='listBarang'>
                  <tr>
                    <th width="6%" height="29"><strong>No</strong></th>
                    <th width="23%">Nama Barang</th>
                    <th width="7%">Spl</th>
                    <th width="13%">Code</th>
                    <th width="32%">Spesifikasi</th>
                    <th width="8%">Qty</th>
                    <th width="11%">Satuan</th>
                  </tr>
 <?php
			$i=1;
			//$total = 0;
			foreach($data as $row)
			{ //qty,nama_brg,spl,code,satuan,speck1,speck2,speck3
			?>
                  <tr>
                    <td align='center'><?php echo $i; ?></td>
                    <td align='center'><input type="text" name="nama_brg" value="<?php echo $row[1]; ?>" size="20"></td>
                    <td align='center'><input type="text" name="spl" value="<?php echo $row[2]; ?>" size="5" /></td>
                    <td align='center'><input type="text" name="code" value="<?php echo $row[3]; ?>"  size="10"/></td>
                    <td align='center'><input type="text" name="speck1" value="<?php echo $row[5]; ?>"  size="2"/>&nbsp;&nbsp;<input type="text" name="speck2" size="2" value="<?php echo $row[6]; ?>" />&nbsp;&nbsp;<input type="text" name="speck3" value="<?php echo $row[7]; ?>" size="2" /></td>
                    <td align='center'><input type="text" name="qty" value="<?php echo $row[0]; ?>"  size="3"/></td>
                    <td align='center'><input type="text" name="satuan" value="<?php echo $row[4]; ?>" / size="5"></td>
                  </tr>
                  
                    <?php
            $i++;
			//$total += ($row[1]*$row[3]);
			}
			?>
                </table>
			 
				    <table width="100%" border="0" cellspacing="0" cellpadding="1">
                  <tr>
                    <td width="84">Keterangan</td>
                    <td width="782" rowspan="2" align="left"><textarea name="notes" cols='60' rows='5' id='notes' style="border:solid 1px #000000; border-collapse:collapse"><?php echo $notes?></textarea></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    </tr>
                </table>				 	  </td>
  </tr>
  <tr>
    <td valign="top" align="left">&nbsp;</td>
    <td colspan="2"><input type="submit" name="bsubmit" value="Save" style="color:#0066ff; background-color:#00ff00">&nbsp;&nbsp;      <input type="button" value="Cancel" class="buttonStyle" onclick="window.location='Indexbbk.php'"  style="color:#0066ff; background-color:#00ff00"/></td>
    </tr>
</table>
        </form>
updateBbk.php


<?php 
include 'conf.php';
 if(isset($_POST['bsubmit'])){
	print_r($_REQUEST);
      
	  	$id 			= $_POST['id'];
	   	$bbk_number 	= $_POST['bbk_number'];
		$so_number		= $_POST['so_number'];
       		$order_number 	= $_POST['order_number'];
		$order_tgl		= $_POST['order_tgl'];
		$tgl			= date('Y-m-d');
		$gudang			= $_POST['gudang'];
		$kategori		= $_POST['kategori'];
        	$notes			= $_POST['notes'];
		$nama_brg       = $_POST['nama_brg'];
		$spl		    = $_POST['spl'];
		$code	        = $_POST['code'];
		$speck1         = $_POST['speck1'];
		$speck2         = $_POST['speck2'];
		$speck3	        = $_POST['speck3'];
		$qty		    = $_POST['qty'];
		$satuan         = $_POST['satuan'];
				
	  		$query_1 = "UPDATE t_bbk a , t_bbkdetail  b SET
					a.bbk_number	 = '$bbk_number',
					a.so_number		 = '$so_number',
					a.order_number	 = '$order_number',
					a.order_tgl		 = '$order_tgl',
					a.gudang		 = '$gudang',
					a.kategori		 = '$kategori',
					a.notes			 = '$notes',
					b.nama_brg		 = '$nama_brg',
					b.spl			 = '$spl',
					b.code			 = '$code',
					b.speck1		 = '$speck1',
					b.speck2		 = '$speck2',
					b.speck3		 = '$speck3',
					b.qty			 = '$qty',
					b.satuan		 = '$satuan'
					
					Where 	a.id=b.id_bbk and a.id='$id'";
 				 mysql_query($query_1) or die(mysql_error());
				
		   
            echo "Data Berhasil disimpan <br>";
   
 		  echo"<script language='javascript'>window.location='indexBbk.php'</script>";

 
    }else{
        header('Location: indexBbk.php');
	   
    }

?>


jika ak gunakn fungsi d atas hny bisa untuk update 1 row pada t_bbkdetail

bgm jk ad 2 atw lebih row yg hrs d update pd t_bbkdetail,,,

thx
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Aug 4, 2012 · 0 Suka · 0 Tidak Suka