[thelist] Quick ColdFusion / SQL question

Benekli benekli at benekli.net
Thu May 3 23:21:03 CDT 2001


No offense intended, but this approach is quite bizarre. 
Dynamic field names? anyway... A query object also returns the 
field names as 'columnList', hence the following will return 'all'
field names and row numbers that match your criteria.


<cfquery name="bnkQ" datasource="bnkD">
   Select *
   From bnkT
   Where 0=0
</cfquery>

<cfparam name="bnkFind" default="4">

ColumnList: <cfoutput>#bnkQ.ColumnList#</cfoutput><br><br>

<cfloop list="#bnkQ.ColumnList#" index="i" delimiters=",">
  <cfoutput query="bnkQ">
    <cfif Evaluate(i) EQ bnkFind>
       <cfset bnkFieldName = ListGetAt(bnkQ.ColumnList,ListFindNoCase(bnkQ.ColumnList,i))>
       Field: <u>#bnkFieldName#</u> contains: #bnkFind# at row: #bnkQ.CurrentRow#<br>
    </cfif>
  </cfoutput>
</cfloop>

Out of pure curiosity, why are the field names dynamic?

Benekli00:21P04V2001
benekli at benekli.net




<->I need a way to select the *field* name of a table based on data in
<->it...for example if this was a table (with fieldXXX, etc. being names
<->of columns):
<->
<->-fieldXXX-  -fieldYYY-   -fieldZZZ-
<->    1           2            4
<->
<->I need to get the value "fieldZZZ" when knowing 4....so kinda like
<->selecting the column name based on data in it (the data in the first
<->row to be exact). Does this make sense? The reason is that the field
<->names are created dynamically.




More information about the thelist mailing list