Skip to main content
Known Participant
February 26, 2010
Question

Getting the NumberofColumns in a resultset

  • February 26, 2010
  • 1 reply
  • 624 views

So I have a query that creates a table of the data after it is submitted, but the results are dependent upon which SELECT fields the user selects via a checkbox.

Example:

I have 3 checkboxes for 3 different fields in the query: Name, Number, Address.  If the user only checks Name and Number, then the SELECT query will be SELECT firstName, number FROM tableofinfo.

So, the resulting table for the results can either be 1, 2 or 3 columns (depending on how many checkboxes they check).  My question is, how can I pull the number of fields or columns that the table resulted in so that I can use that for further manipulation?  So, for the example it would be 2 (Name and Number).  I have the result="resultInfo" set on the <cfquery> tag, and I know that #resultInfo.RecordCount# will give me the number of rows, but I want the number of columns.  Is this possible?

Thanks

    This topic has been closed for replies.

    1 reply

    Inspiring
    February 26, 2010

    cfquery provides a couple of variables.  One of these lists all the columns.  The name of that variable is in the cfml reference manual.  If you don't have one, google cfquery and you'll find what you want lickety split.

    If you don't know what to do with that variable, googling "coldfusion list functions" might give you some ideas.

    depth10Author
    Known Participant
    February 26, 2010

    Yea, columnList is the one you're talking about.  Is there a function that will count resultInfo.ColumnList as an integer?  To the effect of count(resultInfo.ColumnList)?  Something like that where it will provide an integer of 1, 2 or 3?

    Inspiring
    February 26, 2010

    How did you make out with the 2nd paragraph of my previous answer?