Solved

Cold fusion Alphabetical listing

Posted on 2012-04-10
3
293 Views
Last Modified: 2012-06-27
I have a sql directory of names. I want to output an alphabetical listings that displays the alphabet A thru Z, but the letters that contain an actual directory name appear as links.
0
Comment
Question by:swaggrK
  • 2
3 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 37830195
Do you mean a query containing directory names?

ie  DirectoryName
     Aaaaa xxxx
     Cxxxxx
     Dddddd
     .....
0
 

Author Comment

by:swaggrK
ID: 37830506
No.

I mean the following...

Table: tbl_names
Field 1: name_of_company
Field 2: name_of_company_id

Results:
Apple
Burger King
Zerox

Assuming that these are the only three company names in my table,
A, B, Z, would be the only linkable letters.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 175 total points
ID: 37830573
If I'm understanding correctly, you just want to display A-Z and creating make the letter a link only when one (or more) company records exist that start with that letter?

If so, you could run a query to get a unique list of the first letters of existing companies:
             
              <cfquery name="getLetters" ....>
               SELECT   LEFT(name_of_company, 1) AS FirstLetter, COUNT(*)
               FROM     table_names
               GROUP BY LEFT(name_of_company, 1)
             </cfquery>

Then put the results into a list

             <cfset linkableLetters = valueList( getLetters.FirstLetter )>

Then use a loop to generate the letters A - Z, checking #linkableLetters# to see when you should create a link

             <cfoutput>
             <!--- 65 - ascii for upper case "A" --->
             <cfloop from="65" to="90" index="n">
                   <cfset letter = chr( n )>
                   <cfif listFindNoCase(linkableLetters, letter)>
                           <a href="somePage.cfm?letter=#letter#">#letter#</a>            
                   <cfelse>
                           #letter#
                   </cfif>
             </cfloop>
             </cfoutput>

(Not tested, so watch out for typos)
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now