Solved

Cold fusion Alphabetical listing

Posted on 2012-04-10
3
290 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 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

12 Experts available now in Live!

Get 1:1 Help Now