title: dynamically updating select boxes with php mysql ajax
body: <p>I am trying to populate an initial select box with results from mysql via php.  Then I would like the second select box to update with additional information related to what was chosen in the first box.</p>
  
  <p>Here I am selecting some campaign names, then in the second box i would like to update with the versions of the campaign stored in mysql.</p>
  
  <p>here is the name script:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"&gt;  &lt;/script&gt;
      &lt;script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
          $(document).ready(function(){
              $("#campaign").change(function(){
                   var campaign = $("#campaign").val();
                   $.ajax({
                      type:"post",
                      url:"getversion.php",
                      data:"campaign="+campaign,
                      success: function(data) {
                        $("#version").html(data);
                      }
                   });
              });
         });
      &lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
  
      Campaign :
      &lt;select name="campaign" id="campaign"&gt;
        &lt;option&gt;-Select a Campaign-&lt;/option&gt;
      &lt;?php 
      include "db_conn.php"; 
      $result = mysql_query("SELECT campaign, time FROM dfa_data GROUP BY campaign");
      while($row = mysql_fetch_array($result)){
  
      echo "&lt;option value=$row[campaign]&gt;$row[campaign]&lt;/option&gt;";
  
      } ?&gt;
      &lt;/select&gt;
  
  
      Version :
      &lt;select name="version" id="version"&gt;
          &lt;option&gt;-Select a Version-&lt;/option&gt;
      &lt;/select&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>then there is another script that pulls in the second select box data, although it does not populate and I do not have any idea why.</p>
  
  <pre><code>&lt;?php
  include "db_conn.php";
  
  $campaign = $_POST["campaign"];
  
  $result = mysql_query("SELECT * FROM dfa_data where campaign='$campaign' GROUP BY time");
     while($rowa = mysql_fetch_array($result)){
       echo"&lt;option value=$rows[time]&gt;$rows[time]&lt;/option&gt;";
  
     }
  ?&gt;
  </code></pre>
  
  <p>Can anyone show me what I am doing wrong and why the second select box will not populate.  Thanks in advance.</p>