I am stuck in code where I want to get data from MySQL into an array. I have a form containing color and size selection fields, the javascript function is launched onclickand two more selection blocks are created, for example above, I was able to get the data into javascript code, where the code for creating new rectangles is written. But I only get the last inserted record from both tables. Although I used a loop while. Can someone help me, and I get the name of all the selected boxes that I love name="color[]", I want to insert entries into the bridge table containing the color and size identifiers. below is my code please help ..
I will clear it, every time I click the Add More button, it should create 2 new drop-down lists: one for color and 2 for size, both drop-down lists should have different data from the database. so the identifiers for each entry will be the same in each drop-down list, I want to add more than 1 entry to the bridge table that contains product_id, color_id and size_id, so if I go to 3 dropwdown windows and I choose blue and a small size in the first , then for the second drop-down list, I again select the blue color and size of the medium, as well as for the last drop-down menu, which was also created by the javascript function. I choose black color and big size. therefore, from the drop-down list, it will receive the identifiers of size, color, and it will be inserted accordingly. Therefore,when I show the product and the blue color is selected, I would only see the dimensions that were added to the blue color when the product was added .. I hope this clears everything :)
$result=mysql_query("SELECT * FROM color,size");
while($row=mysql_fetch_array($result)) {
?>
<script>
var room = 1;
function add_fields() {
room++;
var objTo = document.getElementById('room_fileds')
var divtest = document.createElement("div");
divtest.innerHTML = '<div class="label">Room ' + room + ':</div><div class="content"><span>Color: <select name="color[]"><option value="<?php echo $row['color_id']; ?>"><?php echo $row['color']; ?></option></select></span><span>Size: <select><option value="<?php echo $row['size_id']; ?>"><?php echo $row['size']; ?></option></select></span></div>';
objTo.appendChild(divtest)
}
</script>
<?php
}
HTML-
<div id="room_fileds">
<div>
<div class='label'></div>
<div class="content">
<input type="button" class="btn btn-success" id="more_fields" onclick="add_fields();" value="Add More" /> <br /><br />
<select name="color[]" class="form-control">
<option value="0">Select Color</option>
<?php
$result=mysql_query("SELECT * FROM color");
while($row=mysql_fetch_array($result)){
?>
<option value="<?php echo $row['color_id'] ?>"><?php echo $row['color']; ?></option>
<?php } ?>
</select>
<select name="size[]" class="form-control">
<option value="0">Select Size</option>
<?php
$result=mysql_query("SELECT * FROM size");
while($row=mysql_fetch_array($result)){
?>
<option value="<?php echo $row['size_id'] ?>"><?php echo $row['size']; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>