title: Populate a PHP Dropdown List from MySQL Database
body: <p>I'm trying to populate a dropdown list in my web page from a mysql database table which has only one column (pathology_id). I know there is test data in there but the best I can do is populate the box with the field name, not the row values. The code I have thus far is below, can anyone suggest how to get more than just the column name? Thanks in advance.</p>
  
  <pre><code>&lt;?php $con = mysql_connect("localhost","dname","dbpass");
      if(!$con)
      {
          die('Could not connect: ' . mysql_error());
      }
  
      $fields = mysql_list_fields("dbname","PATHOLOGY",$con);
      $columns = mysql_num_fields($fields);
      echo "&lt;form action = newcase.php method = POST&gt;&lt;select name = Field&gt;";
      for($i = 0; $i &lt; $columns ; $i++)
      {
          echo "&lt;option value = $i&gt;";
          echo mysql_field_name($columns , $i);
      }
  
      echo "&lt;/select&gt;&lt;/form&gt;";
  
      if(!mysql_query($sql,$con))
      {
          die('Error: ' . mysql_error());
      }
      else
      {
          echo "1 record added";
      }
  
      mysql_close($con) ?&gt;
  </code></pre>