Populating drop down menu from database
Posted: Fri Jul 20, 2007 6:36 am
Sirs,
I would appreciate some help in this matter as im probably going about it all wrong. The goal is to create a drop down menu which is populated from a table in a database and parse the selected item to $POST. The table has one column which is a list of locations. ie Brighton, Warwick, Stockholm etc.
Using a while loop:
I have successfully populated the dropdown with the rows. However they have no "value" to parse to $POST and i am having trouble understanding how to achieve this.
I thought something like
would work and indeed achieves the same result as above however i still have no idea how to capture the selected item as a variable.
This project is for a local charity i have chosen to devote some time to and the system will (eventually) enable select members to mass email contacts by searching the database by location/group.
Any pointers would be greatly appreciated.
I would appreciate some help in this matter as im probably going about it all wrong. The goal is to create a drop down menu which is populated from a table in a database and parse the selected item to $POST. The table has one column which is a list of locations. ie Brighton, Warwick, Stockholm etc.
Using a while loop:
Code: Select all
<select name="Location">
<?php
while ($row = mysql_fetch_array($locationresult, MYSQL_NUM)) {
printf("<option> %s </option>", $row[0]);
}
?>
</select>I thought something like
Code: Select all
while ($row = mysql_fetch_array($locationresult, MYSQL_NUM)) {
printf("<option value = %s> %s", $row[0], $row[0]);
}This project is for a local charity i have chosen to devote some time to and the system will (eventually) enable select members to mass email contacts by searching the database by location/group.
Any pointers would be greatly appreciated.