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

Duplicate items in loop

Status
Not open for further replies.

rdiller

Programmer
Sep 13, 2000
9
US
I'm sending an output from a query, but I only want it to return one instance of each variable...

i.e....

FL instead of FL
CA FL
MI CA
MI
MI

Please assist if possible.

Ryan [sig][/sig]
 
Hi!

2 solutions:
1- Use the DISTINCT word in your query to get only an unique instance if each element

your query
<CFQUERY ...>
SELECT DISTINCT(state_name) FROM states
ORDER BY state_name asc
</CFQUERY ...>

2- Create a loop that would only output some unique element to do so you must order your elements by (in your case) the stateID (state unique identifier in your DB).

your query
<CFQUERY NAME=&quot;state_Get&quot;...>
SELECT * FROM states
ORDER BY stateID asc
</CFQUERY ...>

<CFSET currentState = &quot;&quot;>

<CFOUTPUT QUERY=&quot;state_Get&quot;>
[tab]<CFIF currentState NEQ stateID>
[tab][tab]#state_name#
[tab][tab]<CFSET currentState = stateID>
[tab]</CFIF>
</CFOUTPUT>

Here we go,
Chris [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top