Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

Cold fusion Alphabetical listing

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
swaggrK
Asked:
swaggrK
  • 2
1 Solution
 
_agx_Commented:
Do you mean a query containing directory names?

ie  DirectoryName
     Aaaaa xxxx
     Cxxxxx
     Dddddd
     .....
0
 
swaggrKAuthor Commented:
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
 
_agx_Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now