Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I do this?

Status
Not open for further replies.

buzzt

Programmer
Oct 17, 2002
171
CA
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=&quot;company&quot; class=&quot;formfield1&quot; onchange=&quot;this.form.submit();&quot;>
<?
$result = mysql_query(&quot;select company from stories where active='y' order by company&quot;) or die (mysql_error());
$num_results = mysql_num_rows($result);
?>
<option value=&quot;&quot; selected>Select a Company </option>
<?
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
$comp = $row[&quot;company&quot;];
echo &quot;<option value=\&quot;&quot; . $comp . &quot;\&quot;>&quot; . $comp. &quot;</option>&quot;;
}
?>
</select>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top