Question : ColdFusion Loop Over Query

I am having a difficult time with what I'm sure is a simple query.

I have a form where a user can select several checkboxes.  I want the form to pass the IDs of the checkboxes to a new page, which I am able to do.  However, I am only able to pass the value of the first checkbox ID to the query but I can't figure out how to pass the remaining IDs.

I can't grasp how to loop through the results of the checkboxes stored in the form variable (as a comma delimited list) and get it inside the cfquery.

Thanks in advance.
1:
2:
3:
4:
5:
6:
7:
8:
<cfloop  list="#form.pickThis#" index="ListItem" delimiters=",">
<cfquery name="getIt" datasource="grabdata">  
SELECT event, dateOfCall, orc, typeOne, RepStat, synopsis, pk_id
FROM "tbl_phone"
WHERE pk_id = #ListItem# 
order by "Date/Time of Phone Call" desc
</cfquery>
</cfloop>

Answer : ColdFusion Loop Over Query

No need to loop over the form variable.  The value of the form variable should be a comma delimited listed of numbers.  So you can just use the "IN" statement of the query to fetch all the values.

The cfif statement below is used in case someone didn't check any boxes, then the query would have errored, so this makes sure it just returns no records.

<cfquery name="getIt" datasource="grabdata">  
  SELECT event, dateOfCall, orc, typeOne, RepStat, synopsis, pk_id  
  FROM "tbl_phone"
 <cfif len(form.pickThis)>
  WHERE pk_id in (#form.pickThis#)
 <cfelse>
   where 1=2
 </cfif>
  order by "Date/Time of Phone Call" desc
</cfquery>
Random Solutions  
 
programming4us programming4us