Answered
Need help with QueryToCSV, QueryAddRow, and QuerySetCell
Thanks for taking the time to read my post.
I need to convert a query to a .csv file so users of my family Web site can download it and import it into Outlook or Thunderbird instead of typing in each family member's info.
I've visited many CF blogs that have post about QueryToCSV and QuerySetCell, and found this on Ray Camden's site CFLib.org at http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=556
The code from the above link:
--------------------------------------------------------------------------------------
<cfset test_query = QueryNew("ValueField, DisplayField")>
<cfset QueryAddRow(test_query, 3)>
<cfset QuerySetCell(test_query,"ValueField","blue", 1)>
<cfset QuerySetCell(test_query,"DisplayField","my favorite color is blue", 1)>
<cfset QuerySetCell(test_query,"ValueField","changed the text for the heck of it", 2)>
<cfset QuerySetCell(test_query,"DisplayField","blah blah blah", 2)>
<cfset QuerySetCell(test_query,"ValueField","Louisiana", 3)>
<cfset QuerySetCell(test_query,"DisplayField","The State of Louisiana", 3)>
<cfoutput>
<pre>
#querytoCSV(test_query)#
</pre>
</cfoutput>
--------------------------------------------------------------------------------------
However, I'm stuck because I cannot figure out how to dynamically set the number of columns in the QueryAddRow function and also in the QuerySetCell function. This is needed because the number of registered family members will obviously change with time.
I'm assuming qryMember.RecordCount would work:
(i.e., <cfset QueryAddRow(qryMembers, qryMembers.RecordCount)>) for the QueryAddRow function, but I'm still confused about the QuerySetCell part.
Any suggestions?
Thanks!
I need to convert a query to a .csv file so users of my family Web site can download it and import it into Outlook or Thunderbird instead of typing in each family member's info.
I've visited many CF blogs that have post about QueryToCSV and QuerySetCell, and found this on Ray Camden's site CFLib.org at http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=556
The code from the above link:
--------------------------------------------------------------------------------------
<cfset test_query = QueryNew("ValueField, DisplayField")>
<cfset QueryAddRow(test_query, 3)>
<cfset QuerySetCell(test_query,"ValueField","blue", 1)>
<cfset QuerySetCell(test_query,"DisplayField","my favorite color is blue", 1)>
<cfset QuerySetCell(test_query,"ValueField","changed the text for the heck of it", 2)>
<cfset QuerySetCell(test_query,"DisplayField","blah blah blah", 2)>
<cfset QuerySetCell(test_query,"ValueField","Louisiana", 3)>
<cfset QuerySetCell(test_query,"DisplayField","The State of Louisiana", 3)>
<cfoutput>
<pre>
#querytoCSV(test_query)#
</pre>
</cfoutput>
--------------------------------------------------------------------------------------
However, I'm stuck because I cannot figure out how to dynamically set the number of columns in the QueryAddRow function and also in the QuerySetCell function. This is needed because the number of registered family members will obviously change with time.
I'm assuming qryMember.RecordCount would work:
(i.e., <cfset QueryAddRow(qryMembers, qryMembers.RecordCount)>) for the QueryAddRow function, but I'm still confused about the QuerySetCell part.
Any suggestions?
Thanks!
