ColdFusion Programming/Lists & CFCONTENT

Advertisement


Question
Hello, I'm trying to pass over a variable containing a list via the url, to use inside a cfheader/cfcontent tag that will use this list to extract information from a database that will then be used to create an excel spreadsheet, which a user can download.
Here is the code from the first page:

<cfquery name="get" datasource="lms1">
select userid
...
</cfquery>

<input ype="button" value="Download User(s) Details" class="button1" onClick="window.location='userExcelSheet.cfm?actionId=#get.userId#'">

as you can see the first error here is that even though get.userid is a list of many userIds, I'm not certain how to use a list inside a <input> tag. However, one userid is currently being passed along, but its failing on the next page. Here is the code:

<cfparam  name="actionId" default="">
<cfset session.editUserList = "#actionId#">
<cfoutput>#session.editUserList#</cfoutput>
<cfquery name="getUser" datasource="lms1">
  SELECT * FROM #clientId#..EMP WHERE userId = 'default_user'
  </cfquery>
<cfset userAttributes = getUser.columnlist>
<html>
<head>
<title>Excel User Details</title>
<cfcontent type="application/msexcel">
  <cfheader name="Content-Disposition" value="filename=Employees.xls">
     
     <cfquery name="excelInfo" datasource="lms1">
        SELECT <cfloop from="1" to="#listlen(userAttributes)#" index="i"> #listgetat(userAttributes,i)#<cfif i lt listlen(userAttributes)>,</cfif></cfloop>  
        FROM #clientid#..EMP
        WHERE userid IN (<cfloop from="1" to="#listlen(session.editUserList)#" index="i">'#listgetat(session.editUserList,i)#'<cfif i lt listlen(session.editUserList)>,</cfif></cfloop>)
     </cfquery>
     <!--- to get the column headings --->
     <cfloop from="1" to="#listlen(userAttributes)#" index="i">
     <cfset excelTable = "#listgetat(userAttributes,i)#">
     </cfloop>
     
  <!--- to make a space between the headings and the content --->
     <cfset excelTable = excelTable&chr(13)&chr(10)>
     
  <!--- The content --->   
     <cfoutput query="excelInfo">
     <cfset excelTable = ????>
        #excelTable#
     </cfoutput>
  
  </cfheader>
</cfcontent>

As you can see there are many things wrong with the code, particularly where the ???? is.
Any help would be much appreciated
Thank you

Answer
Aloha,
First do a cfdump of your variable to see what it looks like. To pass it via URL it will have to be a list (not a query). The major thing is to make sure you have delimiters in place and that you know what they are. Your data SHOULD be a comma delimited list but it may not be. Check that first with a <cfdump var="#get.userid#">

ColdFusion Programming

All Answers


Answers by Expert:


Ask Experts

Volunteer


Donald Hammond

Expertise

Expert in ColdFusion, Flash ActionScript, XML, and SQL.

Experience

Cold Fusion, Flash Action Script

©2012 About.com, a part of The New York Times Company. All rights reserved.