Solved

Call nested functions, looping through returned queries

Posted on 2009-07-09
4
214 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
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 update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

776 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