Skip to main content
IvanGn
Participant
Sep 10, 2018 5:55 PM UTC
Answered

Issue with scope variable?

Hi everyone,

I'm having an issue with a certain variable, that is within the scope of my CFOUTPUT.

My variable, TEMPWHO, is not being run under the CFQUERY.

If I put it outside of the output query, it will run, but nothing will show (since its a variable)

However, when I put it inside of the CFOUTPUT query (as shown below), it gives me the error: 'VARIABLE TEMPWHO is not defined', and thus, won't be able to query the data in CFQUERY.

Is there anyway to get around it? (The code that is bolded, is giving me the issue)

  <cfset tempy = getems.RecordCount \ 2>

  <cfset tempx = RandRange(1,tempy)>

<cfif tempx eq 0>

<cfset tempx = 1>

</cfif>

   <cfoutput query="getems" startrow="#TempX#" maxrows="1">

  <cfset tempwho = EmailContact>

   </cfoutput>


<cfquery dbtype="query" name="GetAll">

  SELECT *

   FROM GetNoms, GetStuds

   WHERE GetNoms.EmailContact = '#tempwho#'

   AND GetNoms.IDStudent = GetStuds.IDStudent

   ORDER BY EmailContact, School_Name_Previous

</cfquery>

This topic is closed to new replies. Start a new post to keep the conversation going.
WolfShade
WolfShadeCorrect answer
Legend
Sep 10, 2018 6:53 PM UTC

First of all, the formatting of your code makes it difficult to read.  At the top of the editor, if you highlight your code and click >> and then syntax highlighting, choose a style (I usually use Java) to format the code so we can read it.

Secondly, SELECT * is rarely (if ever) a good idea because it forces the database server to go to a lookup table to get the column names (inefficient.)

Thirdly, have you tried forcing tempwho into the variable scope by prepending "variables." to the variable name?  And use the query name as part of the value.

<cfset variables.tempwho = getems.EmailContact />

HTH,

^ _ ^

1 reply

WolfShade
WolfShadeCorrect answer
Legend
Sep 10, 2018 6:53 PM UTC

First of all, the formatting of your code makes it difficult to read.  At the top of the editor, if you highlight your code and click >> and then syntax highlighting, choose a style (I usually use Java) to format the code so we can read it.

Secondly, SELECT * is rarely (if ever) a good idea because it forces the database server to go to a lookup table to get the column names (inefficient.)

Thirdly, have you tried forcing tempwho into the variable scope by prepending "variables." to the variable name?  And use the query name as part of the value.

<cfset variables.tempwho = getems.EmailContact />

HTH,

^ _ ^

Translate