Solved

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

Posted on 2014-10-02
2
561 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Database structure 4 153
Coldfusion Table display that allows inline edit 3 51
Coldfusion scheduled tasks as one task 2 91
coldfusion upload spreadsheet into the databse 2 51
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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