Solved

Alphabetical List

Posted on 2012-04-02
5
340 Views
Last Modified: 2012-04-02
I have a query and I want to increment each record similar to the #currentrow# function, how can this be accomplished inside the query when the end of the records is not known. The list will not be over 26 letters.

EXample:

query

A
B
C

end query
0
Comment
Question by:-Matthew-
  • 3
5 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 37797154
I don't quite understand the question. Can you post an example of the query data .. and what the desired results look like?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 37797241
Is this what you were asking?

This shows how to access a query's column value directly by the column name and the record number..


<cfloop index="row" from="1" to="#myQuery.recordCount#">

    mQuery["ColumnName"][row]
 
</cfloop>
0
 

Author Comment

by:-Matthew-
ID: 37797266
I want incrementAlphabet to just do that....go to A, B, C, D...

 
<cfquery name="agenda" datasource="source">
SELECT *
from sometable
</cfquery>

 <cfoutput query="agenda"> 

#incrementAlphabet#. #agenda.agenditem#

</cfoutput>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 37797297
Hmm... are you asking how to loop through the query columns dynamically? If that's what you mean, you could adapt gd's example like so

<cfoutput query="yourQuery">
     <!--- you can also use your own list of columns instead --->
     <cfloop list="#yourQuery.columnList#" index="colName">
            #yourQuery[ colName ][ yourQuery.currentRow ]#
       </cfloop>
       <br>
</cfoutput>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 37797306
Oops, our posts crossed.

Assuming the query never contains more than 26 rows, something like this:

<!--- ascii 65 == uppercase A --->
<cfset startLetter = 65>
<cfoutput query="agenda">
     #chr(startletter)#. #agenda.agenditem#
     <cfset startletter = startletter + 1>
</cfoutput>
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

9 Experts available now in Live!

Get 1:1 Help Now