Contoh:
<form name="formalbum" action="simpan-album.php" method="post">
Bulan: <select type="text" name="id_bulan">
<option value="1">January</option>
<option value="2">Feburari</option>
<option value="3">Maret</option>
<option value="4">April</option>
<option value="5">Mei</option>
<option value="6">Juni</option>
<option value="7">Juli</option>
<!-- option bulan lainnya silahkan buat sendiri -->
</select>
<table id="tabel-lagu" cellspacing="0" border="1" cellpadding="3">
<tr>
<td>id_raker</td>
<td>nilai</td>
<td>Delete</td>
</tr>
<tr>
<td><input type="text" name="id_raker[0]"/></td>
<td><input type="text" name="nilai[0]"/></td>
<td><button type="button" class="del">Del</button></td>
</tr>
<tr id="last">
<td colspan="4" align="right"><button type="button" id="addRow">Add</button></td>
</tr>
</table>
<input type="submit" value="Simpan"/>
</form>
<script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
var i = 1;
$(function(){
$("#addRow").click(function(){
row = '<tr>'+
'<td><input type="text" name="id_raker['+i+']"/></td>'+
'<td><input type="text" name="nilai['+i+']"/></td>'+
'<td><button type="button" class="del">Del</button></td>'+
'</tr>';
$(row).insertBefore("#last");
i++;
});
});
$(".del").live('click', function(){
$(this).parent().parent().remove();
});
</script>
untuk menyimpan data:
if($_POST){
$idBulan = $_POST['id_bulan'];
foreach($_POST['id_raker'] as $key => $idRaker){
$nilai = $_POST['nilai'][$key];
$sql = "insert into Detail_Raker (id_raker,nilai,id_bulan)
values ('$idRaker','$nilai','$idBulan')";
mysql_query($sql);
}
}
Ref:
http://ask.myphptutorials.com/questions/view/203
http://www.myphptutorials.com/tutorials/154/menyimpan-data-menampilkan-beberapa-tabel