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!

Alphabetic order

Status
Not open for further replies.

joakimhan

Technical User
Jul 9, 2001
12
SE
I had a problem before with orsering my data And I got help from CFhub and he gave me this solution And it works almost :)

The problem is it only shows one record after each starting Character.

<CFQUERY NAME=&quot;getDomain&quot; DataSource=&quot;mysource&quot;>
SELECT
name,
url,
langid,
Right(name,1) AS FirstChar
FROM domain
GROUP BY
FirstChar
</cfquery>

<cfoutput query=&quot;&quot; group=&quot;&quot;>
#FirstChar#
<cfoutput>
#name# #Url#
</cfoutput>
</cfoutput>


This is the way i would like it to show

A
ABCnews abcnews.go.com
AdWeek ;
Advertising Age ;

Back to top

B
BBC News news.bbc.co.uk
Bloomberg ;
Brandweek

i am new to coldfusion so I hope someone acn help me
 
Instead of your SELECT statement reading
Code:
  GROUP BY
   FirstChar

Make it read
Code:
  ORDER BY 
   FirstChar

Then, your output should look like this:
Code:
<cfoutput query=&quot;getDomain&quot; group=&quot;FirstChar&quot;>
   #FirstChar#
   <cfoutput>
      #name# #Url#
   </cfoutput>
</cfoutput>

The group attribute of the
Code:
<cfoutput>
tag expects the query to be ungrouped but ordered by that field. This should solve your problem.

I also believe that the function you are looking for is LEFT().
 
Thanks for the help, it works like a beauty now.
You guys are the best
:)
Joakim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top