473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

trying to use variables in <cfquery> but they don't convert to values

2
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!
Feb 15 '14 #1
0 5915

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: velu | last post by:
I have created a table MSSQL that contain values and published into Datagrid. The table is typically like this.. Tbl Article Rating Count 1 3 3 2 0 0 3 2 1 4 4 5
1
by: Chris | last post by:
I have a form that has the ID values of various fields from listboxes, etc., which are generated from a db query, assigned to variables. The variables hold the returned $_POST fine, but I also...
31
by: metaperl | last post by:
-- python -i File "<stdin>", line 1 class = "algebra" ^ SyntaxError: invalid syntax Why isn' t the parser smart enough to see that class followed by an identifier is used for class...
4
by: BerkshireGuy | last post by:
I have a form, with a subform that changes AllowsEdits,AllowAdditions, etc depending on who is coming in. This is done by using the OpenArgs and is working fine. However, if the user is...
21
by: St33med | last post by:
Somehow, when I first installed Python 2.5, it wouldn't let me run. I looked up what to do with the environment variables, and it got fixed... Sorta... Then when I wanted to run a program off of...
3
by: Sebarry | last post by:
Hi, var primaryKeyToKeyValue = new Array(); for(var i = 0; i < arguments.length; i++) { var len = document.getElementsByName(arguments).options.length;
1
by: NewHeights | last post by:
Excel 2007- I have a survey that uses radio buttons (3 choices each answer) to select the answer.? My trouble starts with assigning values to the answers (Answer 1 is 0, Answer 2 is 1, Answer 3 is...
7
by: JeremyI | last post by:
This relates to Microsoft Access 2003, file format Access 2000. I am trying to create VBA code that stores values in a table called 1_GlobalVariables, then more code--tied to a different...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.