Link to home
Start Free TrialLog in
Avatar of Mike Waller
Mike WallerFlag for United States of America

asked on

Loop through list, output to csv

Ok, I have this script that loops through a list of ids and it's supposed to output/append each iteration to a csv file but it only outputs data from the first id in the list.  What am I doing wrong?  Here is the script:


<cfset attributes.date = DateFormat(Now(), "yyyymmdd")>

<cfset dailyfile = attributes.date & ".csv"/>
<cfset storageDirectory = "[path to server root]\64\20051229\" />
<cfset filename = storageDirectory & dailyfile />


<cfset choosexid = "71829,73015">

<cfloop index="x" list="#choosexid#">


<cfquery name="dailydump" datasource="aohDB">
select *
from u_user
where id = '#x#'
</cfquery>



<cfset strHeader = '"Field Header"' />
             
<cffile action="write" file="#filename#" output="#strHeader#" addnewline="yes" />
            
<!--- loop through query to spit out the contents --->
<cfset nCount = dailydump.RecordCount />
            
                  <cfloop index="i" from="1" to="#nCount#">
                                          
                  <!--- create a string of the current records data --->
                                          
                  
                  <cfset strCurrentRecord = '"#dailydump.b_lname[i]#"' />
                  
                                          
                  <!--- write the current record to the file --->
                  <cfif i neq nCount>
                  <cffile action="append" file="#filename#" output="#strCurrentRecord#" addnewline="yes" />
                  <cfelse>
                  <cffile action="append" file="#filename#" output="#strCurrentRecord#" />
                  </cfif>
                  
                  </cfloop>
            





</cfloop>
SOLUTION
Avatar of btrevarthen
btrevarthen
Flag of New Zealand 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
Output when I ran that modified code:

                71829 {newline}
            71829 {newline}
            71829 {newline}
            71829 73015 {newline}
            73015 {newline}
            73015 {newline}
            73015
ASKER CERTIFIED SOLUTION
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 Mike Waller

ASKER

Ok, let me try that..