• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Issue with scope variable?

New Here ,
Sep 10, 2018 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>

Views

215

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
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 10, 2018 Sep 10, 2018

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 na

...

Votes

Translate

Translate
LEGEND ,
Sep 10, 2018 Sep 10, 2018

Copy link to clipboard

Copied

LATEST

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,

^ _ ^

Votes

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
community guidelines
Resources
Documentation