title: How do i populate a php dropdown with data relating to a previous dropdown selection
body: <p>my original dropdown works fine:</p>
  
  <pre><code>{function query(){
    $classes = mysql_query("SELECT * FROM class") or die("Could not search!");
    while ($row = mysql_fetch_array($classes)) {    
      echo '&lt;option value="' . $row['class_name'] . '"&gt;' . $row['class_name'] . '&lt;/option&gt;';
    }
  }}
  </code></pre>
  
  <p>The selected value from the dropdown is assigned to the $class variable.</p>
  
  <p>However my second dropdown which is designed to pull all data relating to the $class variable originating from the first dropdown is empty:</p>
  
  <pre><code>{function findpupil(){
    $pupils = mysql_query("SELECT * from pupil WHERE class_name='$class'") or die("Could not search!");
    while ($row = mysql_fetch_array($pupils)) {    
        echo '&lt;option value="' . $row['pupil_id'] . '"&gt;' . $row['pupil_id'] . '&lt;/option&gt;';
      }
    }
  }
  </code></pre>
  
  <p>Both queries are called in HTML like so:</p>
  
  <pre><code>&lt;select class="input username" name="class"&gt;
      &lt;?php query() ?&gt;
  &lt;/select&gt;
  &lt;select class="input username" name="pupil"&gt;
      &lt;?php findpupil() ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Why is the second dropdown empty? All help will be greatly appreciated.</p>