Skip to main content
nikos101
Inspiring
November 28, 2008
Answered

Is there a way to combine their query results into a single function

  • November 28, 2008
  • 3 replies
  • 524 views
say I have a bunch of functions that return a query:

<cffunction name="getDeals" access="remote" returntype="query">
<cffunction name="getDeals2" access="remote" returntype="query">

is there a way to combine their query results into a single function that returns a struct of the various results?

    This topic has been closed for replies.
    Correct answer
    Umm, it's probably more suited to an array - effectively making it into a list of queries. You'd then loop the array and output each.

    I use a similar approach when creating system messages to the user. Most of my functions that are called do their bit, then at the end call another function I call "messages". This function grabs whatever my function sends and appends it to a messages array.

    This way enables me to output a long list of messages - because I could be calling several functions at the same time. If I just output a message from each function, each one would overwrite the other. So I'd get one message at a time.

    Immediately after it's output, I then destroy the message array so that old messages aren't kept inside of it.

    Mikey.

    3 replies

    Inspiring
    November 29, 2008
    sure, just write another function that calls these functions and adds
    each result to a structure which it then returns:

    <cffunction name="getDeals" access="remote" returntype="query">
    ....
    </cffunction>

    <cffunction name="getDeals2" access="remote" returntype="query">
    ....
    </cffunction>

    <cffunction name="getOtherFunctions" returntype="struct">
    <cfset var result = structnew()>
    <cfset result.f1 = getDeals()>
    <cfset result.f2 = getDeals2()>
    <cfreturn result>
    </cffunction>

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Correct answer
    November 28, 2008
    Umm, it's probably more suited to an array - effectively making it into a list of queries. You'd then loop the array and output each.

    I use a similar approach when creating system messages to the user. Most of my functions that are called do their bit, then at the end call another function I call "messages". This function grabs whatever my function sends and appends it to a messages array.

    This way enables me to output a long list of messages - because I could be calling several functions at the same time. If I just output a message from each function, each one would overwrite the other. So I'd get one message at a time.

    Immediately after it's output, I then destroy the message array so that old messages aren't kept inside of it.

    Mikey.
    Inspiring
    November 28, 2008
    Sure, write a function that calls the other ones, puts the queries into a structure, and returns the structure.