I am trying to fill the option values for a select box with those in the database. I want to be able to open all the entries related to the selected company name. The problem here is that the option values display the company name everytime a new entry with that compnay name is added. This means that the select box would have A, B, C, A, A...(A being the company that appears several times in the database). How do I create just 1 instance of each company?
<--start code-->
<select name="company" class="formfield1" onchange="this.form.submit();">
<?
$result = mysql_query("select company from stories where active='y' order by company" or die (mysql_error());
$num_results = mysql_num_rows($result);
?>
<option value="" selected>Select a Company </option>
<?
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
$comp = $row["company"];
echo "<option value=\"" . $comp . "\">" . $comp. "</option>";
}
?>
</select>
<--start code-->
<select name="company" class="formfield1" onchange="this.form.submit();">
<?
$result = mysql_query("select company from stories where active='y' order by company" or die (mysql_error());
$num_results = mysql_num_rows($result);
?>
<option value="" selected>Select a Company </option>
<?
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
$comp = $row["company"];
echo "<option value=\"" . $comp . "\">" . $comp. "</option>";
}
?>
</select>