Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display a query in a dropdown.

Status
Not open for further replies.

eter4

MIS
Mar 13, 2001
30
CA
how can I display the contents of a MySQL table in a dropdown box.

I only need to return 1 column of data.

Ex if I have all the states in a table.... I want to have the states appear in a dropdown list.
Thanks
 
assuming you want the drop down box on a web page and using php, then

1. run your select query

$result = mysql_query("select state_id, state_name from table", $dbconnection);

2.populate your combo

$html_output = '<select name=&quot;states&quot;>';
while($state = mysql_fetch_array($result)) {
$html_output .= '<option value=&quot;'.$state[&quot;state_id&quot;].'&quot;>'.$state[&quot;state_name&quot;].'</option>';
}
$html_output .= '</select>';
echo $html_output;

hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top