Coldfusion list column names

Posted on 2004-11-16
Medium Priority
Last Modified: 2013-12-20
I would like to grab a list of column names from a query where the column value is GT 0. I don't want the column values, but the actual column names, which is proving to be problematic. Anyone have any ideas about how this could be done?
Question by:mjacobs2929
  • 2
  • 2

Assisted Solution

Crazee earned 1000 total points
ID: 12592659
Use the ColumnList property of the query object


LVL 10

Expert Comment

ID: 12593302
Yes Crazee is right use queryName.ColumnList to get the column names. This will return a list width all column names
like: colname1,colname2,colname3

to find out how many column names are in the list use listlen(queryveldtest.ColumnList)
and use cfloop to loop over the list of column names

Author Comment

ID: 12594277
But how do I determine which of the columns have a value EQ 1?
LVL 10

Accepted Solution

Mause earned 1000 total points
ID: 12594396
I'm not sure what you want!
Is it that you want the column name of the column where the value EQ 1

Then it will be someting like this:

<cfloop list="#queryname.ColumnList#" index="columnname">
      <cfif queryname[columnname][1] EQ 1>#columnname#</cfif>

This will loop over all column fields of record 1

Let me know

Author Comment

ID: 12594571
Got it! This is exactly what I wanted...

 <cfset request.pagelevelList="">
 <cfloop list="#getlevel.ColumnList#" index="columnname">
   <cfif getlevel[columnname][1] EQ 1>
    <cfset request.pagelevelList = ListAppend(request.pagelevelList,"#columnname#")>

Many thanks to you both!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

864 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