Outputting Query Results with Unknown Column Names

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Outputting Query Results with Unknown Column Names

    I have been using this code to grab the column headers from a select *
    statement. (I never know what table will be queried out of 12,000 or so. I want
    to loop through the column headers and then the query results in to a web page
    table.

    <cfoutput>
    <cfset colHeaderNames = ArrayToList(recordset1.getColumnList())/>
    #colHeaderNames#
    </cfoutput>

    Is there a similar method or any suggestions for outputting the results of the
    query - now that I know the column headers?

    ctlcal Guest

  2. Similar Questions and Discussions

    1. CF Query Column Names Returned in UPPERCASE
      My Flex application retrieves data from the database using Stored Procedures and Queries in CFCs. However, when I return the query object from the...
    2. counting column and getting column names
      Im using an Access database that will probably be switched over to Oracle later, but I need to find out how to get the number of columns in an...
    3. query results accessed by column/ordinal position
      Is there a way to access query results by column or ordinal position within the recordset? Something like #queryName#.
    4. Outputting query results to excel.. wierd!!
      OK, this is different to my previous posting, so I thought it best to post another to save confusion. I am having some really wierd things...
    5. Query results don't display properly in results table.IGNORE PREVIOUS
      :disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in...
  3. #2

    Default Re: Outputting Query Results with Unknown Column Names

    If I understand correctly, you can do something like the code below.


    <CFLOOP LIST="colHeaderNames" INDEX="i">
    #Evaluate(i)#
    </CFLOOP>
    jdeline Guest

  4. #3

    Default Re: Outputting Query Results with Unknown Column Names

    Thanks for the suggestion, but trying that out it looped through the recordset but just outputted the columnheaders over and over - rather then the field values.
    ctlcal Guest

  5. #4

    Default Re: Outputting Query Results with Unknown Column Names

    Column names and query results.

    Phil

    <table>
    <tr><cfloop list="#recordset1.ColumnList#" index="col" delimiters=",">
    <th><cfoutput>#col#</cfoutput></th>
    </cfloop></tr>
    <cfoutput query="recordset1">
    <tr><cfloop list="#recordset1.ColumnList#" index="col">
    <td>#recordset1[col][CurrentRow]#</td></cfloop></tr>
    </cfoutput>
    </table>

    paross1 Guest

  6. #5

    Default Re: Outputting Query Results with Unknown Column Names

    Hi

    just give ## in side the <cfllop>

    <CFLOOP LIST="#colHeaderNames#" INDEX="i">

    vkunirs Guest

  7. #6

    Default Re: Outputting Query Results with Unknown Column Names

    Great suggestion - But then you lose the actual order of columns and get them back alphabetically, which is why I went with the code above.
    ctlcal Guest

  8. #7

    Default Re: Outputting Query Results with Unknown Column Names

    jdeline and vkunirs - This worked great! Thanks for the help!
    ctlcal Guest

  9. #8

    Default Re: Outputting Query Results with Unknown Column Names

    I was unaware of the getColumnList() method so I have been dong it the "hard
    way", which unfortunately, lists the columns alphabetically. I couldn't find
    getColumnList() documented in LiveDocs, but nothing surprises me any more.

    This other solution is great.

    Phil

    paross1 Guest

  10. #9

    Default Re: Outputting Query Results with Unknown Column Names

    The documentation for "getColumnList" is in the Dreamweaver API Live Docs.
    ctlcal Guest

  11. #10

    Default Re: Outputting Query Results with Unknown Column Names

    Thanks. Since I don't use Dreamweaver it makes sense that I haven't seen this.

    Phil
    paross1 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139