Skip to main content
Inspiring
August 2, 2011
Answered

ok to use a cffunction to output a query ?

  • August 2, 2011
  • 1 reply
  • 2858 views

Is it ok to pass a parameter to a cffunction, perform a select query, then finally output the result ?

Can someone show me how to call the function and output the result of the query ?

<cffunction name="func_getCats" returntype="query">

  <cfargument name="department">

  <cfset var getCat=""/>

  <cfquery name="getCat" datasource=#APPLICATION.datasource#>

    SELECT category

    FROM test

    WHERE department = #arguments.department#

    </cfquery>

  <cfreturn getCat/>

</cffunction>

    This topic has been closed for replies.
    Correct answer -__cfSearching__-

    <cfoutput query=func_getCats()>

    I am saying I do not think that particular syntax is allowed. You probably need to capture the results in a variable. Then use the variable name in your cfoutput.

    (pretend this snippet contains tags)

    cfset result = func_getCats()

    cfoutput query="result"

    #category#

    /cfoutput

    1 reply

    Inspiring
    August 2, 2011

    eg. can you do something like

    <cfoutput query=func_getCats()>

    #category#

    </cfoutput>

    Inspiring
    August 2, 2011

    My gut says no. But only one way to find out. Try it and see.

    Inspiring
    August 2, 2011

    When you say no, do you mean...

    1. Its OK to output a query using a cffunction ? If yes, can you show an example of how to output that query ?

    2. Do you mean its not possible to output it using cfoutput query="....