How do I loop through a file and on each cycle of the loop create an array based on that line from the file split at the comma?
I have a text file and in the file each line has two numbers separated by a comma. I am trying to loop through the file and create an array to be used in a select drop down. One value for the Option and the other to be used as the option value. Please let me know if you have any questions.
So far this is what I have:
<select name="catalog-num" id="catalog-num">
<cfloop file="http://mywebsite.com/catalog-parts.txt" index="PartItem">
<cfset a = listToArray(PartItem)>
<option value="http://newwebsite/product/non-pim-details.cfm?specs_partnum=<cfoutput>#a[0]#</cfoutput>"><cfoutput>#a[1]#</cfoutput></option>
</cfloop>
</select>
My TXT file looks like this:
8018823,C121209HC
8018824,C121609HC
8018828,C162011HC
8018829,C162411HC
8018832,C202013HC
8018852,C24SBASEC
8018854,C66SCOLC
8018653,DFK2016C
8018657,DFK2420C
8018660,DFK2424C
8018661,DFK3024C
ColdFusion arrays start at index 1, so you need to use [1]
and [2]
<select name="catalog-num" id="catalog-num">
<cfloop file="http://mywebsite.com/catalog-parts.txt" index="PartItem">
<cfset a = listToArray(PartItem)>
<option value="http://newwebsite/product/non-pim-details.cfm?specs_partnum=<cfoutput>#a[1]# </cfoutput>"><cfoutput>#a[2]#</cfoutput></option>
</cfloop>