Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The query would need to be present in both cases as the query will not be remembered from one request to another... In the following example the query may not have been created when the second request is made.</p> <pre><code>&lt;cfif StructKeyExists(form, "submit")&gt; &lt;!--- This only gets run on the first request ---&gt; &lt;cfquery datasource="#session.HousingDataSource#" name="query"&gt; ... &lt;/cfquery&gt; &lt;/cfif&gt; &lt;cfif StructKeyExists(form, "export")&gt; &lt;!--- This only gets run on the second request ---&gt; &lt;cfset output = QueryToCSV(query, "studentFirst,studentLast,studentNumber,Detail1,itemDate")/&gt; &lt;cffile action="write" file="#filename#" output="#output#"/&gt; &lt;/cfif&gt; </code></pre> <p>If you update the code as follows then when you export it will run the query again to export it...</p> <pre><code>&lt;cfif StructKeyExists(form, "submit") || StructKeyExists(form, "export")&gt; &lt;!--- This gets run both times ---&gt; &lt;cfquery datasource="#session.HousingDataSource#" name="query"&gt; ... &lt;/cfquery&gt; &lt;/cfif&gt; &lt;cfif StructKeyExists(form, "export")&gt; &lt;cfset output = QueryToCSV(query, "studentFirst,studentLast,studentNumber,Detail1,itemDate")/&gt; &lt;cffile action="write" file="#filename#" output="#output#"/&gt; &lt;/cfif&gt; </code></pre> <p>Or you can save it in the session...</p> <pre><code>&lt;cfif StructKeyExists(form, "submit")&gt; &lt;cfquery datasource="#session.HousingDataSource#" name="query"&gt; ... &lt;/cfquery&gt; &lt;cfset session.query = query/&gt; &lt;/cfif&gt; &lt;cfif StructKeyExists(form, "export") &amp;&amp; StructKeyExists(session, "query")&gt; &lt;cfset output = QueryToCSV(session.query, "studentFirst,studentLast,studentNumber,Detail1,itemDate")/&gt; &lt;cffile action="write" file="#filename#" output="#output#"/&gt; &lt;/cfif&gt; </code></pre> <p>Or the application scope.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload