Reputation: 329
I have a simple form that is pulling data from my datasource. and was wondering if it's possible that I can pull my cfoutput query that I created on my form in my action page?
I have figured out how to pull individual data using POST through the form doing this.
<cfparam name = "form.masternum" default="">
<cfquery name="reloForm" datasource="test"> <!---Not going to list out my real datasource --->
SELECT [testData], [moreTestData]
FROM test.db
WHERE [ORDS##] = #URL.ORDS#
</cfquery>
<form method="post" action="emailaction.cfm">
<label for="masternum">Master Number</label>
<input type="text" name="masternum" value="#reloForm.MASTER#">
<input type="submit" value="SEND">
</form>
I can do this using the name attribute through the form that captures my query variable.
and when I hit the submit button, on my action page I can simply call that variable and it'll output its contents doing this.
#form.masternum#
However, what if I wanted to create another query name and not output it individually but output it on another page using cfoutput query? Heres what I tried.
<cfquery name="funstuff" datasource="test">
SELECT [ITEM], [NOTE]
FROM fun
WHERE [FUNORD##] = #URL.FUNORD#
</cfquery>
<cfoutput query="funstuff"> <!--- How can i capture this information on my action page? this is my question --->
<tr>
<td>#funstuff.ITEM#</td>
<td>#funstuff.NOTE#</td>
</tr>
</cfoutput>
When I try to call #funstuff.ITEM# for example on my action page, my page returns 500 internal server error.
Upvotes: 0
Views: 373
Reputation: 20804
You have choices, each one having it's own pros and cons. In random order:
Put your query in the session scope. The biggest pro is that you only have to write and run it once. Cons include increased RAM useage and the possibility that the values change unexpectedly.
Write your query in a reusable location. This could be a custom tag, UDF, or included file. The pro is that you only write it once. The con is that it's a potentially unnecessary trip to the database.
Same as above, but cache the query. You save the extra trip to the database and still have to write it only once.
There might be other options as well - but none came to my mind.
Upvotes: 0
Reputation: 1738
This is more of an elongated comment than an answer, for now.
I'm not 100% sure what your question is, or how submitting that form relates to a different query on your action page. Maybe I'm misinterpreting things. But you CAN try this to make more sense of that "500 error" you're getting.
Wrap everything you want to test inside a cftry/cfcatch block, then dump the error. It will tell you specifically what is wrong with your code.
<cftry>
<cfquery name="funstuff" datasource="test">
SELECT [ITEM], [NOTE]
FROM fun
WHERE [FUNORD##] = #URL.FUNORD#
</cfquery>
<cfoutput query="funstuff"> <!--- How can i capture this information on my action page? this is my question --->
<tr>
<td>#funstuff.ITEM#</td>
<td>#funstuff.NOTE#</td>
</tr>
</cfoutput>
<cfcatch>
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
Upvotes: 1