<?php include "../koneksi.php"; ?>
	<div class="container1">
		<table class="table" style="width:100%; background-color: white;">
			<thead>
				<th width="40%">Properties</th>
				<th width="20%">Type_Cek</th>
				<th width="20%">Specification</th>
				<th width="20%">Allowance</th>
			</thead>
			<form role="form" id="form-standard" method="post" action="update.php">
			<?php  
			$data1 = mysqli_query ($koneksi, " select * 
												from add_std
												inner join spec
												on add_std.SpecID=spec.SpecID
												where ProductID='$_POST[id]'");
			$hitung = mysqli_num_rows ($data1);
			if($hitung>0) {
			while ($row1 = mysqli_fetch_array ($data1))
			{
			?>
			<tr>
				<td><input type="hidden" name="myprodId[]" id="myprodId[]" value="<?php echo $_POST['id']; ?>">
					<input type="hidden" name="mystdId[]" id="mystdId[]" value="<?php echo $row1['AddStdID']; ?>">
					<select class="form-control" id="mystd[]" name="mystd[]">
					<option value="<?php echo $row1['SpecID']; ?>" selected><?php echo $row1['Spec']; ?></option>
					<?php
					$data = mysqli_query ($koneksi, " select * from spec order by SpecID ASC");
					while ($row = mysqli_fetch_array ($data))
					{
					?>
					<option value="<?php echo  $row['SpecID']; ?>"><?php echo $row['Spec']; ?></option>
					<?php } ?>
				</select>
				</td>
				<td><select class="form-control" id="mytypecek[]" name="mytypecek[]">
					<option value="<?php echo $row1['Type_Cek']; ?>" selected><?php echo $row1['Type_Cek']; ?></option>
					<option value="RANGE">RANGE</option>
					<option value="MAXIMUM">MAXIMUM</option>
					<option value="MINIMUM">MINIMUM</option>
					<option value="BOOLEAN">BOOLEAN</option>
				</select>
				</td>
				<td><input class="form-control" type="text" name="mycl[]" id="mycl[]" value="<?php echo $row1['CL'] ?>"></td>
				<td><input class="form-control" type="text" name="myalw[]" id="myalw[]" value="<?php echo $row1['Allowance'] ?>"></td>
			</tr>
			<?php }} ?>
			
			<tr>
				<td><input type="hidden" name="myprodId[]" id="myprodId[]" value="<?php echo $_POST['id']; ?>">
					<input type="hidden" name="mystdId[]" id="mystdId[]" value="">
					<select class="form-control" id="mystd[]" name="mystd[]">
					<option value="" selected></option>
					<?php
					$data = mysqli_query ($koneksi, " select * from spec order by SpecID ASC");
					while ($row = mysqli_fetch_array ($data))
					{
					?>
					<option value="<?php echo  $row['SpecID']; ?>"><?php echo $row['Spec']; ?></option>
					<?php } ?>
				</select>
				</td>
				<td><select class="form-control" id="mytypecek[]" name="mytypecek[]">
					<option value="" selected></option>
					<option value="RANGE">RANGE</option>
					<option value="MAXIMUM">MAXIMUM</option>
					<option value="MINIMUM">MINIMUM</option>
					<option value="BOOLEAN">BOOLEAN</option>
				</select>
				</td>
				<td><input class="form-control" type="text" name="mycl[]" id="mycl[]"></td>
				<td><input class="form-control" type="text" name="myalw[]" id="myalw[]"></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 = $(".table");
    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="myprodId[]" id="myprodId[]" value="<?php echo $_POST['id']; ?>"><input type="hidden" name="mystdId[]" id="mystdId[]" value=""><select class="form-control" id="mystd[]" name="mystd[]"><option value="" selected></option><?php $data = mysqli_query ($koneksi, " select * from spec order by SpecID ASC"); while ($row = mysqli_fetch_array ($data)) { ?><option value="<?php echo  $row['SpecID']; ?>"><?php echo $row['Spec']; ?></option><?php } ?></select></td><td><select class="form-control" id="mytypecek[]" name="mytypecek[]"><option value="" selected></option><option value="RANGE">RANGE</option><option value="MAXIMUM">MAXIMUM</option><option value="MINIMUM">MINIMUM</option><option value="BOOLEAN">BOOLEAN</option></select></td><td><input class="form-control" type="text" name="mycl[]" id="mycl[]"/></td><td><input class="form-control" type="text" name="myalw[]" id="myalw[]"/></td></tr>'); //add input box
        } else {
            alert('You Reached the limits')
        }
    });

    // $(wrapper).on("click", ".delete", function(e) {
    //     e.preventDefault();
    //     $(this).grandparent().remove();
    //     x--;
    // })
	});
</script>