Skip to main content
tclaremont
Inspiring
January 22, 2009
Question

Values of field returned with ColumnList

  • January 22, 2009
  • 5 replies
  • 737 views
Odd that I have not encountered this before, but here it goes..

I used a select all statement with a maxrows attribute of 1 to return a single record where TransactionID = xxxx. Simple enough..

I used query.ColumnList to return a list of the columns in returned. Works great.

Now I want to display the values associated with the fields. Essentially, I want the dynamic value of a dynamic value.

I want to loop over the table, showing the fieldname, the current value of that field, and an input box allowing the user to change the value. I can do this manually because I know the field names and have access to the backend table, but I want this form to continue working whenever I change the underlying database table for whatever reason. I figured doing it dynamically was the way to go.

I am sure there is an elegent solution that is eluding me.


    This topic has been closed for replies.

    5 replies

    tclaremont
    Inspiring
    January 22, 2009
    Got it. I have used so many variations that I had some fundamental problems. I did this:

    <cfloop list="#GetAll.ColumnList#" index = "col">
    <cfform action="ChangeData.cfm" method="POST">
    <tr>
    <td>#Col#</td>
    <td>#GetAll[col][1]#</td>
    <td><cfinput type="Text" name="NewValue" required="No"></td>
    <td><input type="submit" name="Submit" value="Update"></td>
    </tr>
    </CFFORM>
    </CFLOOP>


    Thanks
    Inspiring
    January 22, 2009
    tclaremont wrote:
    > I must have my notation wrong. Here is what I am starting with:
    >...
    > <cfloop index="FieldName" list="#GetAll.ColumnList#">
    > <cfform action="ChangeData.cfm" method="POST">
    > <tr>
    > <td>#FieldName#</td>
    > <td>#GetAll[FieldName][currentrow]#><</td> <----WHAT IS THE CORRECT
    > NOTATION HERE

    You are missing an <cfoutput query="getAll">...</cfoutput> block around
    all of this. CurrentRow is a a variable contianing the current row
    (imagine that) of a <cfoutput query...> loop iteration.

    You could also do this if you always know your record set only has one row.
    #getAll[FieldName][1]#

    Of course you still need a <cfoutput> block around all variables you
    want to be properly rendered.

    tclaremont
    Inspiring
    January 22, 2009
    I must have my notation wrong. Here is what I am starting with:

    <cfquery name="GetAll" datasource="Finance" maxrows=1>
    SELECT *
    FROM Pharmacy.Transactions
    WHERE TransactionID = '79869'
    </cfquery>

    <table width="50%" border="1">
    <tr bgcolor="#SecondaryColor#">
    <td>Field Name</td>
    <td>Current Value</td>
    <td>New Value</td>
    <td> </td>
    </tr>

    <cfloop index="FieldName" list="#GetAll.ColumnList#">
    <cfform action="ChangeData.cfm" method="POST">
    <tr>
    <td>#FieldName#</td>
    <td>#GetAll[FieldName][currentrow]#><</td> <----WHAT IS THE CORRECT NOTATION HERE
    <td><cfinput type="Text" name="NewValue" required="No"></td>
    <td><input type="submit" name="Submit" value="Update"></td>
    </tr>
    </CFFORM>
    </CFLOOP>
    </table>
    Inspiring
    January 22, 2009
    > I am sure there is an elegent solution that is eluding me.

    Azadi beat me to it, but the key is using array notation as you loop through the query. It lets you access values using a dynamic column name and row number

    #yourQueryName[columnName][rowNumber]#
    Inspiring
    January 22, 2009
    do you mean something like this?

    <cfoutput query="somequery">
    <cfloop list="#somequery.columnlist#" index="col">
    #col# <input type="text" name="#col#"
    value="#somequery[col][currentrow]#"><br />
    </cfloop>
    </cfoutput>


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/