Solved

Call nested functions, looping through returned queries

Posted on 2009-07-09
4
215 Views
Last Modified: 2013-12-24
I'm calling a CFC through a RemoteObject call which passes an ID. Within that function I need to call another function based on the ID. That function returns a query which I then loop through to continuously call another function, which also returns a query, which again calls another function...I'm not sure how to get started...


<cfargument name="_ID1" type="numeric" required="yes">
<cfargument name="_ID2" >
<cfargument name="_1stQ" type="query">
	
<cfset _1stQ= getFirstQuery(#_ID1#)>
		
<cfloop query="_1stQ">
<cfset _get2ndQ= getSecondQuery(#_ID2#)>
</cfloop>

Open in new window

0
Comment
Question by:coldchillin
4 Comments
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 200 total points
ID: 24820111
you are on the right track! that's exactly how one does this, assuming all the other functions you call are in the same cfc.

just don't forget to VAR-scope all variables you create in your function. i.e. in your above code you will need to add <cfset var _get2ndQ = ""> just after the last <cfargument> tag.

also, no need for those # in function calls.

Azadi
0
 
LVL 13

Assisted Solution

by:srikanthmadishetti
srikanthmadishetti earned 150 total points
ID: 24822140
when you are looping the first query  and getting the second query

<cfset _get2ndQ= getSecondQuery(#_ID2#)>


what is this _ID2  is this you pass as an argument or a column of the query which is returned in first query call.

if an argumen which is passed , so in the loop every time ur passing the same variable.

you will be getting out put same query.

if it is a column of the firstquery and u want to pass dynamically to this call


<cfset _get2ndQ= getSecondQuery(#_ID2#)>

you don't need to actually delcare that in arguments section.

and more over where are you storing this query object which you are getting in the loop.



0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 150 total points
ID: 24822795
I agree with srikan.. it seems like some details are needed.

I'm assuming the first ID is passed to the function, but the second ID comes from the first query, otherwise the second query would not make sense.

Here's the same code for that, don't forget you need to scope your variables...

<cffunction name="getData">
  <cfargument name="_ID1" type="numeric" required="yes">
  <!--- removed 1stQ and 2nd ID from arguments because it seems they are not passed in, but are created within the function ----->
  
  <cfset var _1stQ= getFirstQuery(arguments._ID1)> <!---- assuming the ID is passed to the function ---->
  <cfset var _get2ndQ = "">
                
  <cfloop query="_1stQ">
    <cfset _get2ndQ = getSecondQuery(_1stQ.ID)> <!--- assuming the ID comes from the first query ---->
  </cfloop>
 
</cffunction>

Open in new window

0
 
LVL 1

Accepted Solution

by:
coldchillin earned 0 total points
ID: 24938383
Actually, I ended up simply invoking the other methods using a cfinvoke, returning a query, which I then looped and invoked yet another query, and so on... but thanks for all the help!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WCAG (Web Content Accessibility Guidelines) levels 3 101
Coldfusion Complex Structure Reference 4 40
Gulp not seeing Changes 4 73
How can i point a subdomain to directory? 5 30
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question