Solved

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

Posted on 2014-10-02
2
498 Views
Last Modified: 2014-10-02
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

0
Comment
Question by:adam1h
2 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40357024
Not sure what you're trying to do here, the value of getData.currentRow is a number indicating the record number of the current row; 1,2,3.... etc.

<cfset variables.values = replace(variables.getData.currentRow, ",", ";")>

You may want something like this to create a quoted, comma delimited list..

<cfset variables.values = QuotedValueList(variables.getData)>
0
 

Author Comment

by:adam1h
ID: 40357056
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.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now