Jump to content

Populating a Drop Down box using PHP and MySQL


Jamesking56

Recommended Posts

How can I populate a form Drop Down Box using PHP and a MySQL Database??I have tried before:

<form><select name="select"><?php$sql = "SELECT * FROM country";$query = mysql_query($sql); $data = mysql_fetch_array($query);foreach( $data as $row ){		 echo "<option value=" . $row['value'] . ">" . $row['country'] . "</option>";}   		 ?></select></form>

but for some reason it doesn;t display the values right, anyone help?

Link to comment
Share on other sites

You forgot the qoutes.

while($data = mysql_fetch_array($query)){		 echo "<option value=\"" . $data ['id'] . "\">" . $data ['country'] . "</option>";}

btw, why with array. you're selecting the whole table. use the id for the values. array's start at 0 instead of 1.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...