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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic dropdown box

Status
Not open for further replies.

cfhelp

Programmer
Jan 11, 2006
11
US
I am trying to create a drop down box that will display a list of names from a database. The problem is that there might be many different records with the same name in the database with each record having a uniqueID. Here is the code I have so far.

Code:
<cfquery name=&quot;qDistrictNames&quot;>
  select * from District 
</cfquery>

<select name=&quot;DISTRICTID&quot;>
  <cfoutput query=&quot;qDistrictNames&quot;> 
    <option value=&quot;#qDistrictNames.DistrictID#&quot;>#qDistrictNames.DistrictName#</option>
  </cfoutput>
</select>

It doesn't matter which record is used for the DistrictName/DistrictID values as long as only one DistrictName/DistrictID is shown in the drop down box.

Sample data:
DistrictID DistrictName
1354 Los Angles
5637 Los Angles
4533 Los Angles
6763 New York
4654 New York
6743 New York

The drop down box would only show Los Angles and New York. It doesn't matter which record is shown.
 
Try this. I modified the query to allow GROUP BY, and I added group=&quot;DistrictName&quot; to the <cfoutput> tag.

<cfquery name=&quot;qDistrictNames&quot;>
SELECT DistrictID,DistrictName
FROM District
GROUP BY DistrictName,DistrictID
ORDER BY DistrictName
</cfquery>

[COLOR=000080][COLOR=CC3300]<select name=&quot;DISTRICTID&quot;>[/color][/color]
<cfoutput query=&quot;qDistrictNames&quot; group=&quot;DistrictName&quot;>
[COLOR=000080][COLOR=CC3300]<option value=&quot;#qDistrictNames.DistrictID#&quot;>[/color][/color]#qDistrictNames.DistrictName#[COLOR=000080][COLOR=CC3300]</option>[/color][/color]
</cfoutput>
[COLOR=000080][COLOR=CC3300]</select>[/color][/color]
- tleish
 
tleish,

Thanks,that worked perfectly. You are an asset to this community. I have learned tons from lurking about reading your responses.

thanks again,
cfhelp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top