Populate dynamically added select boxes from MySQL Database
<p>I got confused at some point in my project.
The thing I am trying to make here is as following:</p>

<p>Get data from the database
Create a new select box with the button - create
Populate this select box with values from the database
Option to delete that select box through the button - delete</p>

<p>The code I have so far PHP/HTML:</p>

<pre><code>   &lt;button type="button" name="add" onclick="return false;" id="addField" class="nice_button"&gt;Добавить(ADD)&lt;/button&gt;


   &lt;button type="button" name="remove" onclick="return false;" id="remove" class="nice_button"&gt;Удалить(DELETE)&lt;/button&gt;


 &lt;tbody id="documentFields"&gt;
 &lt;tr&gt;
    &lt;td&gt;
        &lt;select size="1" name="hardware[]" style='width:400px;'&gt;
        &lt;option value=""&gt;&lt;/option&gt;
        &lt;?php   while($hardware = $get_hardware-&gt;fetch_array()){
          echo "&lt;option  value='".$hardware['st_id']."'&gt;".$hardware['st_name']." ".$hardware['st_producer']." ".$hardware['st_model']."&lt;/option&gt;";
        }
        ?&gt;
        &lt;/select&gt;
    &lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
</code></pre>

<p>JS script I have so far looks like that:</p>

<pre><code>var g = 1;
var id = [ &lt;? php echo $js_id; ?&gt; ];
$(document).ready(function Product_add() {
    $("#addField").click(function () {
        $("#documentFields").append('&lt;tr id="fieldset_p' + g + '"&gt;&lt;td&gt;&lt;select size="1" name="hardware[]" style="width:400px;"&gt;&lt;option value=""&gt;&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;');
        g++;
    });
});
$(document).ready(function Product_add() {
    $('#remove').click(function () { // similar to the previous, when you click remove link
        if (g &gt; 1) { // if you have at least 1 input on the form
            g--; //deduct 1 from i so if i = 3, after i--, i will be i = 2
            $('#fieldset_p' + g + '').remove(); //remove the last fieldset  
        }
    });
});
</code></pre>

<p>The thing is that I cannot append php function: while, so I cannot populate this select box as the one before.</p>
