datatables for mysql seems wrong - datatables

I have the datatables for coldfusion version 10 for mysql, but there seems to be some syntactical errors i am unable to solve and also the pagination and sorting does not work properly, it tends to keep the processing icon keeps showing even in the console it show 200, it happens on search also
my CFM Code
<cffunction name="getDataForTable" access="remote" returnformat="json" returntype="any" output="false">
<cfargument name="inParam" type="any" default="#{}#">
<cfset var isQueryUsed = structkeyexists(inParam,'queryName') and inParam.queryName neq ''>
<cfif isQueryUsed>
<cfset var qryResults = queryexecute("#PreserveSingleQuotes(inParam.queryName)#",{},{datasource='xxx'})>
</cfif>
<cfset var tableFields = (inParam.queryName neq '') ? qryResults.getMetaData().getColumnLabels() : inParam.Columns/>
<cfset noOfTableFields = ArrayLen(tableFields)>
<cfset searchFields= tableFields>
<cfset noOfSearchFields = ArrayLen(searchFields)>
<cfset start= Int(Val(inParam.start))>
<cfset length= Int(Val(inParam.length))>
<cfset search= Trim(inParam['search[value]'])>
<cfset iSortCol_0= Int(Val(inParam['order[0][column]']))>
<cfif LCase(inParam['order[0][dir]']) EQ 'asc'>
<cfset sSortDir_0='asc'>
<cfelse>
<cfset sSortDir_0='desc'>
</cfif>
<cfset queryWhere="">
<cfif (search NEQ '')>
<cfset queryWhere ="AND (">
<cfloop from="1" to="#noOfSearchFields#" index="counter">
<cfset queryWhere=queryWhere &" lower(#searchFields[counter]#) LIKE '%#Lcase(search)#%' ">
<cfif counter LT noOfSearchFields>
<cfset queryWhere=queryWhere&" OR">
</cfif>
</cfloop>
<cfset queryWhere=queryWhere&")">
</cfif>
<cfif iSortCol_0 NEQ 0>
<cfset queryOrder='ORDER BY #tableFields[iSortCol_0 + 1]# #sSortDir_0#'>
<cfelse>
<cfset queryOrder=''>
</cfif>
<cfif length NEQ 0>
<cfset queryLimit='LIMIT #length# OFFSET #start#'>
<cfelse>
<cfset queryLimit=''>
</cfif>
<cfif isQueryUsed>
<cfquery name="queryResult" datasource="xxx">
#PreserveSingleQuotes(queryName)#
#PreserveSingleQuotes(queryWhere)#
#queryOrder#
#queryLimit#
</cfquery>
<cfquery name="querycount" datasource="xxx">
#PreserveSingleQuotes(queryName)#
#PreserveSingleQuotes(queryWhere)#
#queryOrder#
#queryLimit#
</cfquery>
<cfelse>
<cfquery name="queryResult" datasource="xxx">
select #ArrayToList(tableFields)# FROM #dataTable# #PreserveSingleQuotes(queryWhere)# #queryOrder# #queryLimit#
</cfquery>
<cfquery name="querycount" datasource="xxx">
select count(*) OVER() AS total FROM #dataTable# #PreserveSingleQuotes(queryWhere)# #queryOrder# #queryLimit#
</cfquery>
</cfif>
<cfsavecontent variable="datatablesjson">
<cfloop from="1" to="#queryResult.RecordCount#" index="counter">
<cfoutput>
[
<cfloop from="1" to="#noOfTableFields#" index="innerCounter">
<cfif tableFields[innerCounter] EQ "start_date">
"#JSStringFormat(dateformat(queryResult[tableFields[innerCounter]][counter],'yyyy/mm/dd'))#"
<cfelse>
"#JSStringFormat(queryResult[tableFields[innerCounter]][counter])#"
</cfif>
<cfif innerCounter LT noOfTableFields>
,
</cfif>
</cfloop>
]
<cfif counter LT queryResult.RecordCount>
,
</cfif>
</cfoutput>
</cfloop>
</cfsavecontent>
<cfif queryResult.RecordCount is 0>
<cfset datatablesjson=' [ '>
<cfloop from="1" to="#noOfTableFields#" index="counter">
<cfset datatablesjson=datatablesjson>
<cfif counter LT noOfTableFields>
<cfset datatablesjson=datatablesjson&' , '>
</cfif>
</cfloop>
<cfset datatablesjson=datatablesjson&' ] '>
</cfif>
<cfsavecontent variable="sGrid">
<cfoutput>
{
"draw": #Int(Val(inParam.draw))#,
"recordsTotal": <cfif querycount.recordcount GT 0>#querycount.recordcount#<cfelse>0</cfif>,
"recordsFiltered": <cfif querycount.recordcount GT 0>#querycount.recordcount#<cfelse>0</cfif>,
"data": [#datatablesjson#]
}
</cfoutput>
</cfsavecontent>
<cfreturn sGrid>
</cffunction>
my datatables code
$(document).ready( function () {
var table = $('.display').DataTable({
"order" : [[ 0, "desc" ]],
"stateSave" : true,
"processing" : true,
"serverSide" : true,
"ajax" : "ajaxprocess.cfm"
});
});
ajaxprocess.cfm as :
<cfset sJSON = getDataForTable(url)>
<cfcontent reset="Yes" />
<cfoutput>#trim(sJSON)#</cfoutput>

Related

I am trying to create basic datatables.net and coldfusion server side example but it doesnt seem to works

This example was based on this link
https://datatables.net/forums/discussion/40613/datatable-jquery-server-side-with-adobe-cold-fusion-and-sql-server
and i am using datatable version 1.10
On first page load, all data sucessfully loaded into #formsTable
But it wont work when clicking sorting,searching and paging.
It just hang with 'processing..'
pageA.cfm (only show scripting part here...)
<script type="text/javascript">
$(document).ready(function(){
$('#formsTable').DataTable({
processing:true,
serverSide:true,
ajax:{
url:'pageB.cfm'
},
columns:[
{title: "id",data:'id'},
{title: "Name",data:'name'},
{title: "Emp.No",data:'empno'},
{title: "IC",data:'ic'}
]
})
})
</script>
pageB.cfm (server-side)
<cfcontent reset="true">
<cfset listColumns = "id,emp_no,emp_name,number_id2" />
<cfset sIndexColumn = "id" />
<cfparam name="draw" default="1" type="integer" />
<cfparam name="start" default="0" type="integer" />
<cfparam name="length" default="10" type="integer" />
<cfparam name="url.sSearch" default="" type="string" />
<cfparam name="url.iSortingCols" default="0" type="integer" />
<!--- query data --->
<cfquery datasource="hrms" name="qFiltered">
select id,emp_no,emp_name,number_id2 from employee
<cfif len(trim(url.sSearch))>
Where
(
<cfloop list="#listColumns#" index="thisColumn">
<cfif thisColumn neq listFirst(listColumns)>
OR
</cfif>
#thisColumn# LIKE <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="%#trim(url.sSearch)#%" />
</cfloop>
)
</cfif>
<cfif url.iSortingCols gt 0>
ORDER BY
<cfloop from="0" to="#url.iSortingCols-1#" index="thisS">
<cfif thisS is not 0>, </cfif>
#listGetAt(listColumns,(url["iSortCol_"&thisS]+1))#
<cfif listFindNoCase("asc,desc",url["sSortDir_"&thisS]) gt 0>
#url["sSortDir_"&thisS]#
</cfif>
</cfloop>
</cfif>
</cfquery>
<!--- query data count --->
<cfquery dbtype="query" name="qCount">
SELECT COUNT(#sIndexColumn#) as total
FROM qFiltered
</cfquery>
<!--- Output --->
{"draw": <cfoutput>#val(draw)#</cfoutput>,
"recordsTotal": <cfoutput>#qCount.total#</cfoutput>,
"recordsFiltered": <cfoutput>#qFiltered.recordCount#</cfoutput>,
"aaData": [
<cfoutput query="qFiltered" startrow="#val(start+1)#" maxrows="#val(length)#">
<cfif currentRow gt (start+1)>,</cfif>
{
"id":#SerializeJSON(qFiltered.currentrow)#,
"name":#SerializeJSON(qFiltered.emp_name)#,
"empno":#SerializeJSON(qFiltered.emp_no)#,
"ic":
<cfif trim(qFiltered.number_id2) neq '[empty string]'>
#SerializeJSON(qFiltered.number_id2)#
<cfelse>
""
</cfif>
}
</cfoutput> ] }
I am stuck here , it seems that something is missing on pageB.cfm ?
Edited:
thanks for #user12031119 pointing out that sent parameter from pageA.cfm to pageB.cfm is different now with v1.10, so basically these parameters should be change :-
sEcho : draw
iDisplayStart : start
iDisplayLength : length
iTotalRecords : recordsTotal
iTotalDisplayRecords : recordsFiltered
with that change i can now click on next/prev page (paging) but still search and sorting dont work
Yes, unfortunately the code sample you're viewing on datatables.net is for legacy datatables. Under datatables 1.10.x, you will have to use the upgraded keys which version 1.10 expects in your returned json structure. It looks like you already updated pageA.cfm with the new parameters, however you also need to update your server-side return parameters in pageB.cfm.
Here's a guide to upgrade to version 1.10 https://datatables.net/upgrade/1.10
Here's a guide for the new parameters for server-side 1.10 https://datatables.net/manual/server-side
Edit 1 thanks to James A Mohler
Edit 2 per issue noticed by myself
Apparently I was mistaken that datatables only accepts an array of arrays when returned from the server. Apparently it also accepts an array of structs, which helps simplify my answer. However, this will require aliasing the columns in the select statement to match the column definitions defined in pageA.cfm. With that said, here are the changes needed.
The first code modification to pageB.cfm will be to alias the columns in your select statemen to match their definition in pageA.cfm.
<cfquery datasource="hrms" name="qFiltered">
select id as id, emp_no as empno, emp_name as name, number_id2 as ic from employee
Once that's done, change the following in your <cfoutput> block from pageB.cfm
Change sEcho to draw
Change iTotalRecords to recordsTotal
Change iTotalDisplayRecords to recordsFiltered
Change aaData to data
Use serializeJson() with the "struct" option to return an array of structs with the key values matching up to how you defined them in pageA.cfm. If you're using ACF instead of lucee, then you might have to change your column definitions in pageA.cfm to uppercase since ACF doesn't preserve case and uppercases key names.
<!--- Output --->
<cfoutput>
{
"draw": #val(url.sEcho)#,
"recordsTotal": #qCount.total#,
"recordsFiltered": #qFiltered.recordCount#,
"data": #serializeJson(qFiltered, "struct")#
}
</cfoutput>
First, check that your JSON output is valid (jsonlint.com)
Then, wrap your JSON output into a cfsavecontent:
<cfsavecontent variable="json">
<cfoutput>
your output here
</cfoutput>
</cfsavecontent>
Then use this code to return the JSON:
<cfset lastModDate = DateFormat(Now(),'ddd, dd mmm YYYY') & ' ' & TimeFormat(DateConvert('local2Utc', Now()), 'HH:mm:ss') & ' GMT'>
<cfheader name="Expires" value="#DateAdd('m', -1, Now())#">
<cfheader name="Last-Modified" value="#lastModDate#">
<cfheader name="cache-control" value="must-revalidate">
<cfheader name="Pragma" value="no-cache">
<cfcontent type="text/x-json" />
<cfoutput>#json#</cfoutput>
OK finally it works now.
So this is it, basic datatables.net coldfusion/lucee server side example.
Datatables Version 1.10.xx
Language Coldfusion/lucee
pageA.cfm (scripting)
<script type="text/javascript">
$(document).ready(function(){
$('#formsTable').DataTable({
processing:true,
serverSide:true,
ajax:{
url:'pageB.cfm',
type :'post'
},
columns:[
{title: "id",data:'id'},
{title: "Name",data:'name'},
{title: "Emp.No",data:'empno'},
{title: "IC",data:'ic'}
],
language: {
infoEmpty: "No records available",
}
})
})
</script>
pageB.cfm
<cfcontent reset="true">
<cfset listColumns = "id,emp_no,emp_name,number_id2" />
<cfset sIndexColumn = "id" />
<cfparam name="draw" default="1" type="integer" />
<cfparam name="start" default="0" type="integer" />
<cfparam name="length" default="10" type="integer" />
<cfparam name="search" default="" type="string" />
<cfif len(form["search[value]"]) gt 0>
<cfset search=form["search[value]"]>
</cfif>
<!--- Data set after filtering --->
<cfquery datasource="hrms" name="qFiltered">
select id,emp_no,emp_name,number_id2 from employee
<cfif len(trim(search))>
where
(
<cfloop list="#listColumns#" index="thisColumn">
<cfif thisColumn neq listFirst(listColumns)>
OR
</cfif>
#thisColumn# LIKE <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="%#trim(search)#%" />
</cfloop>
)
</cfif>
<cfif form["order[0][column]"] gt 0>
ORDER BY
<cfif form["order[0][column]"] eq '1'>
emp_name <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '2'>
emp_no <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '3'>
number_id2 <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
</cfif>
</cfquery>
<!--- Total data set length --->
<cfquery dbtype="query" name="qCount">
SELECT COUNT(#sIndexColumn#) as total
FROM qFiltered
</cfquery>
<cfif qFiltered.recordcount gt 0>
<cfset recordsTotal=#qCount.total#>
<cfelse>
<cfset recordsTotal=0>
</cfif>
<!---
Output
--->
{"draw": <cfoutput>#val(draw)#</cfoutput>,
"recordsTotal": <cfoutput>#recordsTotal#</cfoutput>,
"recordsFiltered": <cfoutput>#qFiltered.recordCount#</cfoutput>,
"data":
<cfif qFiltered.recordcount gt 0>
[
<cfoutput query="qFiltered" startrow="#val(start+1)#" maxrows="#val(length)#">
<cfif currentRow gt (start+1)>,</cfif>
{
"id":#SerializeJSON(qFiltered.currentrow)#,
"name":#SerializeJSON(qFiltered.emp_name)#,
"empno":#SerializeJSON(qFiltered.emp_no)#,
"ic":
<cfif trim(qFiltered.number_id2) neq '[empty string]'>
#SerializeJSON(qFiltered.number_id2)#
<cfelse>
""
</cfif>
}
</cfoutput> ]
<cfelse>
""
</cfif>
}

Issue with pagination using SQL Server and JQgrid,

I have the following code where from the query I'm trying to get the first 500 records and then next 500 and so on .
Here is my code, I'm stuck as to what and where I should make the change to make it work
<cffunction name="queryConvertForJQGRID" access="package" returntype="struct" output="no">
<cfargument name="q" type="query" required="yes">
<cfargument name="page" type="numeric" required="no" default="1">
<cfargument name="rows" type="numeric" required="no" default="10">
<cfset var result = structnew()>
<cfset var rowStruct = structnew()>
<cfset var col = "">
<cfset result["page"] = arguments.page>
<cfset result["total"] = ceiling(arguments.q.recordcount/arguments.rows)>
<cfset result["records"] = arguments.q.recordcount>
<cfset result["rows"] = arraynew(1)>
<cfoutput query="arguments.q" startrow="#(arguments.page-1)*arguments.rows+1#" maxrows="#arguments.rows#">
<cfset rowStruct = structnew()>
<cfset rowStruct['viewed'] = viewed>
<cfset rowStruct['id'] = q['id'][currentrow]>
<cfset rowStruct['status'] = q['status'][currentrow]>
<cfset rowStruct['template'] = q['template'][currentrow]>
<cfset rowStruct['line'] = q['line'][currentrow]>
<cfset rowStruct['error_message'] = q['error_message'][currentrow]>
<cfset rowStruct['error_type'] = q['error_type'][currentrow]>
<cfset rowStruct['datein'] = q['datein'][currentrow]>
<cfset arrayappend(result.rows, rowStruct)>
</cfoutput>
<cfreturn result />
</cffunction>
<cffunction name="getgrouped" returntype="any" access="remote" output="false">
<cfargument name="table" required="true" default="errors">
<cfargument name="usedsn" default="" required="true">
<cfargument name="callback" default="" required="false">
<cfargument name="page" required="no" default="1">
<cfargument name="rows" required="no" default="500">
<cfargument name="sidx" required="no" default="">
<cfargument name="sord" required="no" default="ASC">
<cfargument name="acelem" required="no" type="any">
<cfset var dsn = dsnSettings(arguments.usedsn)>
<cfset var groupedget = "">
<cfset var result = structnew()>
<cfset var rowStruct = structnew()>
<cfset var col = "">
<cfset result["rows"] = arraynew(1)>
<cfquery name="groupedget" datasource="#dsn#">
WITH List AS (
SELECT row_number() over(ORDER BY mi.id) AS rowNum
, viewed
, status
, mi.errorid
, FORMAT(datein, 'MMMM d, yyyy h:mm:ss tt PST', 'en-US') AS datein
, mi.error_message
, upper(mi.error_type) AS error_type
, mi.line
, mi.template
, mi.id
FROM #arguments.table# mi
)
, ListRecordCount AS (
SELECT *
FROM List , ( SELECT MAX(rowNum) AS recordCount FROM List ) recordCount
)
SELECT *
FROM ListRecordCount
WHERE rowNum BETWEEN #page# AND #rows#
</cfquery>
<cfset q = groupedget>
<cfreturn queryConvertForJQGRID(q, arguments.page, arguments.rows)>
</cffunction>
But it queries only 500 rows and that's it, no more pagination happening in the JQgrid.

Edited - some PDFs generated are corrupt - using ColdFusion

Edit - There are some customer accounts that are reporting a $0 balance due on their online accounts but there is an actual balance due. It is with these accounts only that the PDFs will not open. Data import issue at this point?
I have a set of CF functions in which new PDFs are generated from database records and available on user accounts for download or viewing. The code has worked great up until a couple weeks ago, but now the new or old (previous monthly bills) PDFs will not open (corrupt) on the user account pages. The record data has not been changed or modified. Could this be CF update issue or what could have caused files to now generate corrupt? Any help is appreciated.
PDF Analysis of the corrupt PDF files gives:
PDF Errors:
Open file.
0x80410108 - E - The end-of-file marker was not found.
- File: 11118749.pdf
0x8041010A - E - The 'startxref' keyword or the xref position was not found.
- File: 11118749.pdf
0x80410108 - E - The end-of-file marker was not found.
- File: 11118749.pdf
Close file.
CF PDF Generation Code:
<cfcomponent>
<!---***************************************************************************--->
<cffunction name="getBill" access="public" returntype="query">
<cfargument name="billID" required="yes" default="">
<cfquery name="getPayment" datasource="#application.dsnName#" username="****" password="****">
SELECT * FROM ccos_cust_bill
WHERE billID = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.billID#">
</cfquery>
<cfreturn getPayment>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="getCustBills" access="public" returntype="query">
<cfargument name="accountNum" required="yes" default="">
<cfquery name="getCustBills" datasource="#application.dsnName#" username="****" password="****">
SELECT * FROM ccos_cust_bill
WHERE accountNum = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.accountNum#">
ORDER BY billDate DESC, billID DESC
</cfquery>
<cfreturn getCustBills>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="addBill" access="public" returntype="string">
<cfargument name="formvalues" required="yes" default="">
<cfquery name="addBill" datasource="#application.dsnName#" username="****" password="****">
INSERT INTO ccos_cust_bill (billID, accountNum, billDate, dueDate, billTotal)
VALUES (
<cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.formvalues.billID#">,
<cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.formvalues.accountNum#">,
<cfqueryparam cfsqltype="cf_sql_date" maxlength="20" value="#DateFormat(arguments.formvalues.billDate, "yyyy-mm-dd")#">,
<cfqueryparam cfsqltype="cf_sql_date" maxlength="20" value="#DateFormat(arguments.formvalues.dueDate, "yyyy-mm-dd")#">,
<cfqueryparam cfsqltype="cf_sql_decimal" scale="2" maxlength="20" value="#arguments.formvalues.billTotal#">
)
</cfquery>
<cfset addOK = "Y">
<cfreturn addOK>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="getBillPDF" access="public" returntype="query">
<cfargument name="billID" required="yes" default="">
<cfargument name="accountNum" required="yes" default="">
<cfquery name="getPayment" datasource="#application.billsDsnName#" username="****" password="****">
SELECT * FROM ccos_bills
WHERE billID = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.billID#">
AND accountNum = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.accountNum#">
</cfquery>
<cfreturn getPayment>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="getNextDueDate" access="public" returntype="string">
<cfargument name="accountNum" required="yes" default="">
<cfquery name="getNextDueDate" datasource="#application.dsnName#" username="****" password="****" maxrows="1">
SELECT dueDate FROM ccos_cust_bill
WHERE accountNum = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.accountNum#">
AND dueDate >= <cfqueryparam cfsqltype="cf_sql_date" maxlength="20" value="#DateFormat(now(), "yyyy-mm-dd")#">
ORDER BY dueDate
</cfquery>
<cfreturn getNextDueDate.dueDate>
</cffunction>
<!---***************************************************************************--->
</cfcomponent>
CF View PDF Code:
<cfparam name="URL.billID" default="">
<cfset getBillPDF = application.billCFC.getBillPDF('#URL.billID#','#session.accountNum#')>
<cfif getBillPDF.RecordCount GT 0>
<cfoutput query="getBillPDF">
<cfset fileData = "#BinaryDecode(billData, "Base64")#">
<cfheader name="content-disposition" value="inline; filename=#billID#.pdf" />
<cfcontent type="application/pdf" variable="#fileData#" />
</cfoutput>
<cfelse>
You are not authorized to view this bill.
</cfif>
PDF Import into Database
<!--- CCOS Bill PDF Data --->
<cfquery name="deleteData" datasource="#application.billsDsnName#" username="#application.billsDsnUser#" password="#application.billsDsnPass#">
DELETE FROM ccos_bills WHERE billDate < '#DateFormat(DateAdd("d", -180, now()), "yyyy-mm-dd")#'
</cfquery>
<!--- Check to see how many files Exist --->
<cfdirectory action="list" directory="#ExpandPath('.')#\files" name="filelist">
<cfset fileCount = 0>
<cfoutput query="filelist">
<cfif name CONTAINS "ccos_cust_bill_pdf"><cfset fileCount = fileCount + 1></cfif>
</cfoutput>
<!--- Loop over the files and Load the new data --->
<cfloop from="1" to="#fileCount#" index="i">
<cfquery name="insertData" datasource="#application.billsDsnName#" username="#application.billsDsnUser#" password="#application.billsDsnPass#">
LOAD DATA LOCAL INFILE '#Replace(ExpandPath('.'), "\", "\\", "ALL")#\\files\\ccos_cust_bill_pdf#i#.txt' IGNORE
INTO TABLE `ccos_bills`
FIELDS OPTIONALLY ENCLOSED BY '"'
TERMINATED BY '|'
<!---IGNORE 1 LINES--->
(`accountNum`, `billID`, `billDate`, `billData`);
</cfquery>
</cfloop>
<cfquery name="fixbillDate" datasource="#application.billsDsnName#" username="#application.billsDsnUser#" password="#application.billsDsnPass#">
UPDATE ccos_bills SET dateCreated = '#DateFormat(now(), "yyyy-mm-dd")#' WHERE dateCreated IS NULL
</cfquery>
<!---***********************************************************************************--->

Outputting dynamic variables

Why can I not make my textbox show only what the user has entered?
<cfinput
type="text"
name="firstname_#Add#"
value="#form['firstname_#Add#']#"
>
I have also researched and tried changing to
<input
type="text"
name="firstname_#Add#"
value="<cfoutput>#form['firstname_#Add#']#</cfoutput>"
>
<cfloop index="Add" from="1" to="#session.checkout.quantity.pcount#" step="1">
<cfset session.checkout.info["firstname_#Add#"]="">
<cfparam name="form['firstname_#Add#']" default="session.checkout.info.firstname_#Add#">
</cfloop>
<cfif structKeyExists(form, "submit")>
<cfset errors = []>
<cfif not arrayLen(errors)>
<cfloop index="Add" from="1" to="#session.checkout.quantity.pcount#" step="1">
<cfset session.checkout.info["firstname_#Add#"]=form["firstname_#Add#"]>
</cfloop>
Where am I going wrong? Instead of being blank it is showing the session variable (session.checkout.info.firstname_#Add#") then instead of saving it when the user hits a link back to that page it changes what they have entered back to (session.checkout.info.firstname_#Add#"). Anyone have any ideas?
You're telling that CFPARAM to use the text "session...", not the value of "session...". This should get you what you want:
<cfparam name="form['firstname_' & Add]" default="#session['checkout.info.firstname_' & Add]#">

coldfusion create list from query results

I am currently using Binding to grab values from a database. Depending on what the user selects from a pull down it shows the results from the database. Currently I am able to show one result but I need to show multiple results if the query brings back more then 1 value. Here is my current code.
<cffunction name="getServiceType" access="remote" returnType="array">
<cfargument name="CATG_NAME" type="string" required="true">
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<cfquery name="getServiceType" datasource="#dsource#">
select distinct SRTY_NAME
from Somedatabase
where (CATG_SPRS_NAME = <cfqueryparam value="#ARGUMENTS.CATG_NAME#" cfsqltype="cf_sql_varchar"> OR CATG_DEPT_SPRS_NAME = <cfqueryparam value="#ARGUMENTS.CATG_NAME#" cfsqltype="cf_sql_varchar">) AND EVLN_REQD_FLAG IS NOT NULL
order by SRTY_NAME
</cfquery>
<cfloop index="i" from="1" to="#getServiceType.recordcount#">
<cfset result[i][1]=getServiceType2.SRTY_NAME[i]>
<cfset result[i][2]=getServiceType2.SRTY_NAME[i]>
</cfloop>
<cfreturn result>
</cffunction>
This generates the 1st pull down list
<cffunction name="getUnion" access="remote" returnType="array">
<cfargument name="SRTY_NAME" type="string" required="true">
<cfset var result=ArrayNew(1)>
<cfquery name="union_rq" datasource="#dsource#">
select U.UNI_NAME, S.SRTY_NAME
from Somedatabase U JOIN Someotherdatabase S ON U.SRTY_NBR = S.SRTY_NBR
where S.SRTY_NAME = <cfqueryparam value="#ARGUMENTS.SRTY_NAME#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfset result[1]=union_rq.UNI_NAME>
<cfreturn result>
</cffunction>
The first list would have an option list Hotel Training and the second query should show both Maids and Cooks. Right now it only shows Maids. I tried to create a list or another array but have not be able to get it to display the results. Below is my Coldfusion call for the display. It is fine to display with commas between the results like Maids,Cooks
<tr id="union">
<td></td>
<td>Union Attached:
<cfinput name="uni_name"
bind="cfc:servicetype.getUnion({service_type})"
bindonload="false"
/></td></tr>
Any advice would be greatly appreicated.