Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
dobaldwin #1
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
-
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... -
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... -
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:... -
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... -
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: ... -
dobaldwin #2
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



Reply With Quote

