Link to home
Start Free TrialLog in
Avatar of theaussie
theaussie

asked on

Populating a dropdown box with data from a MySQL table.

I am attempting to populate a dropdown menu with data from a table.

The tableX consists of 5 fields.
id
field1
field2
field3
field4

I need the information if database.field3 to popualte the dropdown box, and am using the following script:

<?  
$connection = mysql_connect("localhost","user","passwordr");
$fields = mysql_list_fields("database", "tableX", $connection);
$columns = mysql_num_fields($fields);
echo "<form action=page_to_post_to.php method=POST><select name=Field>";
for ($i = 0; $i < $columns; $i++) {
echo "<option value=$i>";
echo mysql_field_name($fields, $i);
}
echo "</select></form>";
?>    

This though populates the dropdown with the field names:
id
field1
field2
field3
field4

and not the specific data in field 3.

What am I missing here.?
SOLUTION
Avatar of ldbkutty
ldbkutty
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW, why B !?