Populate a PHP Dropdown List from MySQL Database

kalleybeali

New Member
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.\[code\]<?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 "<form action = newcase.php method = POST><select name = Field>"; for($i = 0; $i < $columns ; $i++) { echo "<option value = http://stackoverflow.com/questions/3889230/$i>"; echo mysql_field_name($columns , $i); } echo "</select></form>"; if(!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; } mysql_close($con) ?>\[/code\]
 
Back
Top