title: Loop by number of Columns in CSV upload Coldfusion
body: <p>I'm customizing a CSV uploader to allow for column mapping. I've got a function that parses it into an Array, then I'm looping through it to generate select boxes with the uploaded file column names to map to existing column names in the corresponding table in my DB.</p>
  
  <p>I can get the select drop downs to populate with the column names, but I can't figure out how to loop through the amount of columns in the uploaded file to limit the total amount of select dropdowns.</p>
  
  <p>Function after it's parsed:</p>
  
  <pre><code>&lt;!--- Get Value from Array based on Column Name ---&gt;
  &lt;cffunction name="ValByColName" access="public" returntype="string" output="false"&gt;
      &lt;cfargument name="ColName"type="string" required="true" default=""/&gt;
      &lt;cfargument name="DataArray" type="array" required="true" default=""/&gt;
      &lt;cfset findValue = keyArray.indexOf(#ColName#) + 1&gt;
      &lt;cfreturn(#DataArray[findValue]#) /&gt; 
  &lt;/cffunction&gt;
  </code></pre>
  
  <p>LOOP:</p>
  
  <pre><code>&lt;!--- Set Uploaded file to Array ---&gt;
                  &lt;cfset arrCSV = CSVToArray(CSVFilePath = #form.UploadedFile#,Delimiter = ",",Qualifier = """") /&gt;
                  &lt;!--- Create Key array from column names ---&gt;
                  &lt;cfset keyArray = ArrayNew(1)&gt;
                  &lt;cfloop from="1" to="#DON'T KNOW WHAT TO PUT HERE" index="t"&gt;
                      &lt;!--- Variable Headers ---&gt;
                      &lt;cfif Len(form.UploadedFile) GTE 5&gt;
                          &lt;cftry&gt;
  
                              &lt;select name="HeaderID" class="search" id="Header"&gt;
                              &lt;option selected value=""&gt;--- Headers Uploaded ---&lt;/option&gt;
                              &lt;cfoutput&gt;
                              &lt;cfloop from="1" to="1" index="i"&gt;
  
                                  &lt;cfloop from="1" to="#ArrayLen(arrCSV[i])#" index="j"&gt;
  
                                       &lt;option name="HeaderID" value="#j#"&gt;#arrCSV[i][j]#&lt;/option&gt;
  
                                  &lt;/cfloop&gt;
                              &lt;/cfloop&gt;
                              &lt;/cfoutput&gt;
                              &lt;/select&gt; =
                      &lt;/cftry&gt; 
  
                      &lt;/cfif&gt;
                      &lt;cfquery name="clientsCols" datasource="#request.dsn#"&gt;
                          select Column_name 
                          from Information_schema.columns 
                          where Table_name like 'Clients'
                      &lt;/cfquery&gt;
                      &lt;!--- Constants---&gt;
                      &lt;cfif Len(form.UploadedFile) GTE 5&gt;
                          &lt;cftry&gt;
                              &lt;select name="ColumnID" class="search" id="Column"&gt;
                              &lt;option selected value=""&gt;--- Headers Clients ---&lt;/option&gt;
                              &lt;cfoutput&gt;
                                  &lt;cfloop query="clientsCols"&gt;
                                  &lt;option name="ColumnID" value="#Column_name#"&gt;#Column_name#&lt;/option&gt;
                                  &lt;/cfloop&gt;
                              &lt;/cfoutput&gt;
                              &lt;/select&gt;&lt;br /&gt;&lt;br /&gt;
                      &lt;/cftry&gt; 
  
                      &lt;/cfif&gt;
                  &lt;/cfloop&gt;
  </code></pre>