I'm not highly technical, and this is probably something simple, but here is
my dilemma, where I am attempting to retrieve a single record using a variable name in the query.
First, I define some variables:
<cfset datasource = 'MyDatabase'>
<cfset query_tbl = 'MyDatabaseTable'>
<cfset field1 = 'actual_fieldname1'><!--- FIRST field in MyDatabaseTable --->
<cfset field2 = 'actual_fieldname2'><!--- SECOND field in MyDatabaseTable --->
<cfset ID = #Form.ID#<!--- ONE particular record I want to retrieve, passed from a form --->
I do a test display to ensure all variables are set, and everything checks out fine.
Then, to retrieve this single record, I run a query using those variables:
<cfquery name="cfqGetItem" datasource="#datasource#">
SELECT *
FROM #query_tbl#
WHERE ID = #ID#
</cfquery>
Then, I attempt to display the query output:
EITHER AS
<cfoutput>
<p>#cfqGetItem.field1#
</cfoutput>
OR, AS
<cfoutput>
<p>#cfqGetItem[column1_field][currentRow]#
</cfoutput>
In each case, I get a similar CF error message: "Element field1 is not defined in query cfqGetItem", or "Variable currentrow is not defined".
How do I get the query output to generate the actual values for the record?
How can a "translation" be done? What would be the correct way?
Thank you very much for any help!