ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 25th, 2005, 10:51 AM
rigante rigante is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 56 rigante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 16 m 45 sec
Reputation Power: 4
simple cfoutput question. (stumpped)

Hi All,

I have a very simple <cfoutput> query question.

I have two independent queries:
<cfquery name="clients" datasource="#request.dsn#">
Select id as Clid, clientName from clients_temp
where id = 1
</cfquery>


<cfquery datasource="#request.dsn#" name="agency">
Select id as agid, agencyName from agency_temp
</cfquery>


The first query retrieves 1 record
Second query retrieves 2 records.

I then run a loop.


<cfoutput query="agency">
#agid#
<cfloop query="clients">
#agid# <br>
</cfloop>
</cfoutput>
Agency query retieves values for the id field called agid.
I wanna use the value of the outer query inside the loop of the second query. But agid within the second loop/query gives me a "variable undefined error".

But if I set to a temp variable, it wrks.
Eg:
<cfoutput query="agency">
<cfset tempVar = #agid#> #agid#
<cfloop query="clients">
#tempvar# <br>
</cfloop>
</cfoutput>

I can also use valuelist to run a similar scenario.
<cfoutput query="agency">
<cfloop list="#valuelist(clients.clid)#" index="counter" >
#agid# <br>
</cfloop>
</cfoutput>

Why cant I get the first scenario to work.

Why cant I access the outer query variable in the inner query ?

Any suggestions or leads are appreciated.

tx,
rigante

Reply With Quote
  #2  
Old April 25th, 2005, 11:29 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
First, always prefix your query variables with the query name (ie #clients.id# if the query was named clients.

Also, I'm not understanding why you'd want to return all of the agencies...isn't the idea to only return the agency that the client is assocaited with? And if that is the case, is there a reason why you aren't doing this in one query using a join?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old April 25th, 2005, 11:51 AM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 25 m 11 sec
Reputation Power: 5
Quote:
Originally Posted by rigante
<cfoutput query="agency">
#agid#
<cfloop query="clients">
#agid# <br>
</cfloop>
</cfoutput>
Agency query retieves values for the id field called agid.
I wanna use the value of the outer query inside the loop of the second query. But agid within the second loop/query gives me a "variable undefined error".


Does your outer loop actually loop the same information as does the inner loop? Or is the repition of #agid# in both loops, just for testing/our purposes?

Reply With Quote
  #4  
Old April 25th, 2005, 11:58 AM
rigante rigante is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 56 rigante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 16 m 45 sec
Reputation Power: 4
I tried scoping it to agency.agid

Say the values of agid in the agency table is 1,2 . (Two records)

But putting agency.id shows me only the same value, though the loop runs twice
Eg:
1,1 when its sorted asc
and 2,2 when sorted desc


On another note:
When you do <cfoutput>#agency.agid#</cfoutput>. It would return only one value. The last record in most of the cases.


what happens to agid when its accessed in the inner loop ?
It has no problems when its outside the inner loop.

A friend asked me this question, I didnt believe him till I created a temp db table and wrote the above queries.

It might take about 5 mins to set up an this table schema. Its too much to ask. But can u give it a shot?

Cause I dont understand why I cant access the current value of an outer query in an inner querry? without putting it to a variable ?

tx

Reply With Quote
  #5  
Old April 25th, 2005, 12:03 PM
rigante rigante is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 56 rigante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 16 m 45 sec
Reputation Power: 4
bastion,

Quote:
<cfoutput query="agency">
#agid#
<cfloop query="clients">
#agid# <br>
</cfloop>
</cfoutput>


The display of agid inside and outside the inner loop is for testing purposes.

Both the tables have id. So I have renamed those to

For the clients table
Select id as Clid,

For the agency table
Select id as agid,

Reply With Quote
  #6  
Old April 25th, 2005, 12:09 PM
rigante rigante is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 56 rigante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 16 m 45 sec
Reputation Power: 4
Therotically speaking, this what I thought should be happening.

Values for agid = 1,2 (2 records)
Values for aDESC = google, yahoo
Values for clid = 1 (1 record)


First round of the loop
agid = 1 --- aDESC= google --- Clid= 1

Second round of the loop
agid = 2 --- aDESC= yahoo --- Clid= 1


The point is the outer loop(Agency query) runs twice and the inner loop runs once.
Please dont look into the logic part now.

Reply With Quote
  #7  
Old April 25th, 2005, 01:24 PM
rigante rigante is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 56 rigante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 16 m 45 sec
Reputation Power: 4
I just heard from a reliable source that "You need to set to a variable." before using it in the inner loop.

<cfoutput query="x">
<cfset Tempvar = QryVar>
<cfoutput query="y">
#TempVar#
</cfoutput>
</cfoutput>

dang,

I dont whether to call it a feature or a bug

Reply With Quote
  #8  
Old April 25th, 2005, 02:32 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
What version of CF are you using?

Reply With Quote
  #9  
Old April 25th, 2005, 02:55 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
After some testing, it does look to me like you need to copy the var into a temp variable in order for the inner loop to see it properly. I had thought this was fixed in CFMX 6.1 but I guess it has not. I'll try it on 7 to see if it is still an issue.

Reply With Quote
  #10  
Old April 25th, 2005, 03:03 PM
rigante rigante is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 56 rigante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 16 m 45 sec
Reputation Power: 4
kiteless,

Tx for testing though.

I am running this on CFMX 6.1

Reply With Quote
  #11  
Old April 25th, 2005, 03:26 PM
rigante rigante is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 56 rigante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 16 m 45 sec
Reputation Power: 4
kiteless,

Tx for testing though.

I am running this on CFMX 6.1

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > simple cfoutput question. (stumpped)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT