title: PHP/SQL duoble drop down from SQL table
body: <p>I have a nested drop down choice where, basically, the second select input should update its content depending on first selected option.
  I get it working ok when it open the page but did not exactly understood how to update the variable once the page is loaded. As a matter of fact if the last option of the SQL table in the first option match the name of one or more record in the second input those may correctly be selected but - changing the option - the second input box doesn’t update. 
  I tried some java but hadn’t succeeded, also thought about AJAX. Can any one help me with that?</p>
  
  <p>My code is following, the $namev variable is the one, I guess, should need some correct action to be handled toward second input box:</p>
  
  <p></p>
  
  <pre><code>&lt;head&gt;
  </code></pre>
  
  <p>…..</p>
  
  <pre><code>    &lt;/head&gt;
  
  
  &lt;body&gt;
  </code></pre>
  
  <p>…..</p>
  
  <pre><code>        &lt;form&gt;
  </code></pre>
  
  <p>…….</p>
  
  <pre><code>            &lt;div class="divFLOATleft"&gt;
                  &lt;label&gt;voce&lt;/label&gt;
                      &lt;?php
  
                          $result = $conn-&gt;query("select id_voce,id_gruppo_voce,gruppo_voce,voce FROM voci");
                          echo "&lt;select name='voce'&gt;&lt;option value='' disabled selected&gt;scegli voce&lt;/option&gt;";
  
                          while ($row = $result-&gt;fetch_assoc()) {
  
                                                                  unset($idv, $namev);
                                                                  $idv = $row['id_voce'];
                                                                  $namev = $row['voce']; 
                                                                  $id_gv = $row['id_gruppo_voce'];
                                                                  $id_v = $row['gruppo_voce'];                                                                    
                                                                  echo '&lt;option value="'.$idv.'"&gt;'.$namev.'&lt;/option&gt;';
  
                                                              }
                              echo "&lt;/select&gt;";
  
  
  
                              echo"&lt;/div&gt;";
  
                              echo"&lt;div class='divFLOATleft'&gt;";
                              echo"&lt;label&gt;categoria&lt;/label&gt;";
  
  
                          $result = $conn-&gt;query("select id_voce,id_gruppo_voce,gruppo_voce,voce FROM voci WHERE gruppo_voce LIKE '$namev'");
                          echo "&lt;select name='voce'&gt;&lt;option value='' disabled selected&gt;scegli categoria&lt;/option&gt;";
  
                          while ($row = $result-&gt;fetch_assoc()) {
  
                                                                  unset($id, $name);
                                                                  $idc = $row['id_voce'];
                                                                  $namec = $row['voce']; 
                                                                  $id_gc = $row['id_gruppo_voce'];
                                                                  $id_c = $row['gruppo_voce'];
                                                                  echo '&lt;option value="'.$idc.'"&gt;'.$namec.'&lt;/option&gt;';
  
                                                              }
                              echo "&lt;/select&gt;";
                      ?&gt;
  
              &lt;/div&gt;                  
  
  
          &lt;/form&gt;
  </code></pre>
  
  <p>…..</p>
  
  <pre><code>&lt;/body&gt;
  </code></pre>
  
  <p></p>