title: How to populate a drop down based on previous drop down selection SQL
body: <p>I have been following This solution<a href="https://stackoverflow.com/questions/11237900/first-drop-down-menu-to-auto-change-the-options-of-a-second-dropdown" title="This solution">1</a> to create a drop down list the changes based on the users previous selection in another dropdown higher in the page. However I was unsure what I need to do at the  Options would have been initially populated here </p>
  
  <p><strong>Thanks</strong></p>
  
  <pre><code>&lt;?php
  mysql_connect('localhost');
  mysql_select_db("test");
  $result = mysql_query("SELECT * FROM `contents` WHERE `parent` = 0");
  echo "&lt;select name='name'&gt;";
  while(($data = mysql_fetch_array($result)) !== false)
      echo '&lt;option value="', $data['id'],'"&gt;', $data['name'],'&lt;/option&gt;'
  ?&gt;
  
          &lt;select onchange="ajaxfunction(this.value)"&gt;
          &lt;!-- Options would have been initially populated here --&gt;
              &lt;/select&gt;
          &lt;select id="sub"&gt;    
              &lt;/select&gt;
  
     &lt;script type="text/javascript"&gt; function ajaxfunction(parent)
  {
  $.ajax({
      url: 'process.php?parent=' + parent;
      success: function(data) {
          $('#sub option').remove();  //// here sub is the id of second select box
          $('#sub').append(data)
      }
  });
  }
  &lt;/script&gt;
  </code></pre>