<?php
	include "../koneksi.php";
	$data = mysqli_query ($koneksi, " select 
									  QtyPlan
									  from 
									  plan
									  where PlanID = $_POST[id]");
	$row = mysqli_fetch_array ($data);
	
?>
	<div class="container1">
		<table class="tableinput" style="width:100%; background-color: white;">
			<thead>
				<th scope='col' style="text-align: center;">Kode</th>
				<th scope='col' style="text-align: center;">Nomor Lot</th>
				<th scope='col' style="text-align: center;">No Nick</th>
			</thead>
			<form role="form" id="form-standard" method="post" action="update.php">
			<?php  
			include "../koneksi.php";
			$data1 = mysqli_query ($koneksi, "SELECT * FROM stpj
													INNER JOIN plan
													ON stpj.PlanID=plan.PlanID
													WHERE stpj.PlanID='$_POST[id]'");
			$hitung = mysqli_num_rows ($data1);
			if($hitung>0) {
			while ($row1 = mysqli_fetch_array ($data1))
			{
			?>
			<tr>
				<td><input type="hidden" name="myplanId[]" id="myplanId[]" value="<?php echo $_POST['id']; ?>">
					<input type="hidden" name="mystpjId[]" id="mystpjId[]" value="<?php echo $row1['STPJ_ID']; ?>">
					<input type="hidden" name="myqty[]" id="myqty[]" value="<?php echo $row['QtyPlan']; ?>">
					<input class="form-control" type="text" name="mykode[]" id="mykode[]" value="<?php echo $row1['Kode'] ?>">
				</td>
				<td><input class="form-control" type="number" name="mylot[]" id="mylot[]" value="<?php echo $row1['NoLot'] ?>"></td>
				<td><input class="form-control" type="number" name="mynick[]" id="mynick[]" value="<?php echo $row1['Nick'] ?>"></td>
			</tr>
			<?php }} ?>
			
			<tr>
				<td><input type="hidden" name="myplanId[]" id="myplanId[]" value="<?php echo $_POST['id']; ?>">
					<input type="hidden" name="myqty[]" id="myqty[]" value="<?php echo $row['QtyPlan']; ?>">
					<input type="hidden" name="mystpjId[]" id="mystpjId[]">
					<input class="form-control" type="text" name="mykode[]" id="mykode[]">
			</td>
				<td><input class="form-control" type="number" name="mylot[]" id="mylot[]"></td>
				<td><input class="form-control" type="number" name="mynick[]" id="mynick[]"></td>
			</tr>
			</form>
		</table>
	</div>
	<button class="add_form_field btn btn-primary"> Tambah Properties &nbsp; 
		<span style="font-size:16px; font-weight:bold;">+ </span>
	</button>


<script>
	$(document).ready(function() {
    var max_fields = 35;
    var wrapper = $(".tableinput");
    var add_button = $(".add_form_field");

    var x = 1;
    $(add_button).click(function(e) {
        e.preventDefault();
        if (x < max_fields) {
            x++;
            $(wrapper).append('<tr><td><input type="hidden" name="myplanId[]" id="myplanId[]" value="<?php echo $_POST['id']; ?>"><input type="hidden" name="myqty[]" id="myqty[]" value="<?php echo $row['QtyPlan']; ?>"><input type="hidden" name="mystpjId[]" id="mystpjId[]"><input class="form-control" type="text" name="mykode[]" id="mykode[]"></td><td><input class="form-control" type="number" name="mylot[]" id="mylot[]"></td><td><input class="form-control" type="number" name="mynick[]" id="mynick[]"></td></tr>'); //add input box
        } else {
            alert('You Reached the limits')
        }
    });

	});
</script>