Re: trying 2 pull data out table and populate a list box
| From: | Rens Admiraal | Date: | Thu, 28 Oct 2004 16:00:10 +0000 |
| Subject: | Re: trying 2 pull data out table and populate a list box | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-200549@lists.php.net to get a copy of this message | ||
you mean:
$query = " SELECT ProvinceID, Description FROM province ORDER BY Description ASC ";
$result = @mysql_query ($query, $connection) or die (mysql_error());
while ($row = @mysql_fetch_array($result))
{
$options .= "<option value='{$row["ProviceID"]}'>{$row["Description"]}</option>\n";
}
$selectBox = "<select name='Provinces'>\n" . $options . "</select>\n";
echo $selectBox;
You can also set the selected item by using:
$query = " SELECT ProvinceID, Description FROM province ORDER BY Description ASC ";
$result = @mysql_query ($query, $connection) or die (mysql_error());
$selectedID = "1";
while ($row = @mysql_fetch_array($result))
{
$options .= "<option value='{$row["ProvinceID"]}'";
if ($row["ProvinceID"] == $selectedID)
{
$options .= " selected";} $options .= ">{$row["Description"]}</option>\n"; } $selectBox = "<select name='Provinces'>\n" . $options . "</select>\n"; echo $selectBox; Garth Hapgood - Strickland wrote:
I am trying to pull all data out of a table called "province" which has 2 fields "ProvinceID" and "Description" respectively. Now I want to populate a list with all the data in the "descriptions" field. Many thanx