Re: trying 2 pull data out table and populate a list box

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux