Reference Column Name by string...

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Reference Column Name by string...

    If you read half way through my question and think to yourself, "Huh?" you will
    know exactly how I feel right now.

    I am dynamically creating a form from a database table named "form_fields."
    form_fields has many column, among which are "form_fields.field_name,"
    "form_fields.field_label," "form_fields.field_type"... Each row in this table
    represents a field in a cooresponding form.

    Here is a sample query from the table "form_fields":

    field_name | field_label | field_type
    -----------------------------------------------
    first_name | First Name: | text
    last_name | Last Name: | text
    field_6 | Price Range | select

    I am storing this data in a second table called "data." The column names
    coorespond to the data in form_fields.field_name from above. In other words, I
    have 3 columns named "first_name," "last_name," and "field_6." This is really
    easy to put things into the database. I just do this:

    INSERT INTO data(id<cfloop
    query="getformfields">,#getformfields.field_name#</cfloop>)
    VALUES(1<cfloop
    query="getformfields">,'#FORM[getformfields.field_name]#'</cfloop>)

    Which essentially turns into:

    INSERT INTO data(first_name,last_name,field_6)
    VALUES('#FORM[first_name]#','#FORM[last_name]#','#FORM[field_6]#')

    So now comes the question...

    I want to represent this data in the following format:

    First Name: Jack
    Last Name: Johnson
    Price Range: $5-$10

    Can you kind of see my dilemma? I can't do this like I did with the form:

    <cfloop query="getformfields">
    #getformfields.field_label# #getdata[getformfields.field_name]#<br>
    </cfloop>

    So how do I reference the data column using the field_name data from my
    form_fields table?

    I know this was a long and winded question. I would appreciate any insight on
    this. My hat is off to you.

    dobaldwin Guest

  2. Similar Questions and Discussions

    1. Reference a Column in a Dynamic Query
      I'm creating a simulated a dynamic crosstab query from my SQL 2K table by looping over a recordset and creating my SQL statement. Everthing works...
    2. How to reference cells once converted to Template Column
      Life is easy when I use a simple bound column. I refer to it as: MyString = e.Item.Cells(2).Text As soon as I convert this column to a Template...
    3. How to sort a String column as Numeric?
      I have a datagrid (dgResults) that I am populating from a SQL stored procedure. After I fill my dataset (ds), I cache the dataset this way:...
    4. Update portion of a string column
      Hi, I have a column that has a string field, and I only wanna update the 3rd character in the string. e.g. change 'StRing' to 'String'. Is this...
    5. Hyperlink Template Column w Query String
      Hi, I need to bind data to a datagrid and have a custom hyperlink column that has multiple elements in the querystring: ...
  3. #2

    Default Re: Reference Column Name by string...

    This is what I was looking for:

    <cfloop query="query1">
    #query1.field1#
    #Evaluate("query2.#query1.field#")#
    </cfloop>
    dobaldwin 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