Highlighted

Issue with scope variable?

New Here ,
Sep 10, 2018

Copy link to clipboard

Copied

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>

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,

^ _ ^

Views

142

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Issue with scope variable?

New Here ,
Sep 10, 2018

Copy link to clipboard

Copied

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>

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,

^ _ ^

Views

143

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 10, 2018 0
LEGEND ,
Sep 10, 2018

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 10, 2018 0