Solved

Call nested functions, looping through returned queries

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

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now