Link to home
Start Free TrialLog in
Avatar of adam1h
adam1hFlag for Belgium

asked on

How to convert dynamically a query row to a list, in Coldfusion

Hi experts,

I have to loop into a query and to output data to a csv file.

My problem is that I want to get the full record (row) and have the different values separate by a semi-colon.
But I can just do something like the following, because there are commas into the data.
<cfset variables.values = replace(variables.getData.currentRow, ",", ";")>

Open in new window


Do you know a trick to achieve this ? Thanks a lot.

Here is the code I’m trying to use :
<cfquery name="variables.getData" datasource="joecool_web">
	select * from jcstktabl where jcid = '#listgetAt('#variables.index#',1, ';')#'
</cfquery>
<!--- build the product’s file --->
<cfif variables.getData.RecordCount NEQ 0>
	<cfset variables.values = replace(variables.getData.currentRow, ",", ";")>
	<cffile action="append" file="#variables.productsFile#" output="#variables.values#" addnewline="true" charset="iso-8859-1">
</cfif>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adam1h

ASKER

Hi gdemaria,

Indeed, I misunderstood the currentrow function.

Knowing this, coupled with this infos (source), I have correct the statement as follow :
<cfquery name="variables.getData" datasource="joecool_web">
	select * from jcstktabl where jcid = '#listgetAt('#variables.index#',1, ';')#'
</cfquery>
<!--- build the product’s file --->
<cfif variables.getData.RecordCount NEQ 0>
	<cfset variables.values = "">
	<cfloop index="variables.ColumnName" list="#variables.getData.ColumnList#">
		<cfset variables.values &= variables.getData[variables.ColumnName][variables.getData.currentRow]>
	</cfloop>
	<cffile action="append" file="#variables.productsFile#" output="#variables.values#" addnewline="true" charset="iso-8859-1">
</cfif>

Open in new window


I will test it but I think it’s that good way to do it.