Solved

Call nested functions, looping through returned queries

Posted on 2009-07-09
4
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
What You Need to Know when Searching for a Webhost Provider
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…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

691 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