title: dynamic dropdown filled from mysql data
body: <p>What i'm trying to do is display a drop down with all field names from mysql database, once the user picks one and submits the form i want to display a second dropdown filled with all the rows from the submitted field name, this is my code so far:</p>
  
  <pre><code>$result = mysql_query("select * from `parts`") or die(mysql_error());
  
  echo "&lt;form action='".$_SERVER['PHP_SELF']."' method='post'&gt;";
  echo "&lt;select name='field_names'&gt;";
  
  $i = 0;
  while ($i &lt; mysql_num_fields($result)) {
    $fieldname = mysql_field_name($result, $i);
    echo '&lt;option value="'.$fieldname.'"&gt;'.$fieldname.'&lt;/option&gt;';
    $i++;
  }
  
  echo "&lt;/select&gt;";
  echo "&lt;input type='submit' value='submit'&gt;&lt;/input&gt;";
  echo "&lt;/form&gt;";
  
  if($_POST) {
    $fields = $_POST['field_names'];
    $result1 = mysql_query("select '".$fields."' from `parts`") or die(mysql_error());
    echo '&lt;select name="fields"&gt;';
  
    while ($row = mysql_fetch_array($result1)) {
      echo "&lt;option value=".$row[$fields]."&gt;".$row[$fields]."&lt;/option&gt;";
    }
    echo '&lt;/select&gt;';
  }
  </code></pre>
  
  <p>Can anyone spot where i'm going wrong, thanks</p>