Skip to main content
April 20, 2009
Answered

setting the results of a query to a variable

  • April 20, 2009
  • 3 replies
  • 560 views

Hi all,

     I'm having a problem setting the results of a query to a variable. What I'm trying to do is make an AJAX call to a .cfc file and pass back the results of the function. The main problem is, I'm trying to pass back a block of HTML code ( resulting from a cfquery to a cfoutput ) stored in a variable. My code is something like..

<cffunction name="getText" access="remote" returntype="void">

        <cfquery datasource="#request.dsn#" name="queryTable">
            SELECT  infoA, infoB

            FROM  infoTable

        </cfquery>

       
        <cfset result = '<!--- this is the part I'm stuck on, I want the table to go here. --->'>

              <table>
                  <cfoutput query="tablequery">
                  <tr>
                  <td>#infoA#</td><td>#infoB#</td>
                  </tr>
                  </cfoutput>
              </table>


    <cfwddx action="cfml2js" input="#result#" toplevelvariable="r">

</cffunction>

This is a simplified version of what I want to do, but you get the idea..

Is this even the right way of going about it??  Thanks

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer ilssac

That is what I get for trying the e-mail reply feature!  Aren't you glad I double checked my post.

You could do a bunch of string concatenation here doing stuff like  <cfset result = result & "<td>" & infoA & "</td><td>" & infoB & "</td>">  over and over again.  But really the <cfsaveContent...> tags is so much  easier to use.

<cfsaveContent variable="result">

<table>
<cfoutput query="tablequery">
   <tr>
     <td>#infoA#</td><td>#infoB#</td>
   </tr>
</cfoutput>
</table>

</cfsaveContent>

3 replies

ilssac
ilssacCorrect answer
Inspiring
April 20, 2009

That is what I get for trying the e-mail reply feature!  Aren't you glad I double checked my post.

You could do a bunch of string concatenation here doing stuff like  <cfset result = result & "<td>" & infoA & "</td><td>" & infoB & "</td>">  over and over again.  But really the <cfsaveContent...> tags is so much  easier to use.

<cfsaveContent variable="result">

<table>
<cfoutput query="tablequery">
   <tr>
     <td>#infoA#</td><td>#infoB#</td>
   </tr>
</cfoutput>
</table>

</cfsaveContent>

April 20, 2009

You are the best. I didn't even think of that. Thanks so much for the help!

ilssac
Inspiring
April 20, 2009