Answered
cfloop help
I have an edit form where I display records for line item 1,
records for line item 2, and records for line item 3. Each
output/display is based on a flag, so I use <cfif flag is
.....> to determine what to display for each line item. This
works good, so far.
The problem that I am running into is when I attempt to update the table with the changes. I use an index loop, from 1 to number of records, in this case 3. I want to update each record at a time. However, the first column that it attempts to update, quantity, blows up. The form shows item 1 with quantity 100, item 2 with quantity 2, and item 3 with quantity 5. The sql error shows that I am attempting to update quantity = '100,2,5'.
I though the loop would take care of it but I guess not.
Here is my code for the loop, what am I doing wrong ?
<cfquery name="qryUpdate_ref_Line_Items" datasource="db">
<cfloop index="i" from="1" to="#form.max_line_Item#">
update TableName
set quantity = '#form.quantity#',
<cfif form.ref_action is "Receive">
po_number = '#form.po_number#',
item = '#form.item#',
part_number = '#form.part_number#'
<cfelseif form.ref_action is "NRC">
tracking_number = '#form.tracking_number#'
<cfelseif form.ref_action is "Other">
instructions = '#form.instructions#'
</cfif>
where ref_number = '#form.ref_number#'
and ref_line_item = '#i#'
</cfloop>
</cfquery>
The problem that I am running into is when I attempt to update the table with the changes. I use an index loop, from 1 to number of records, in this case 3. I want to update each record at a time. However, the first column that it attempts to update, quantity, blows up. The form shows item 1 with quantity 100, item 2 with quantity 2, and item 3 with quantity 5. The sql error shows that I am attempting to update quantity = '100,2,5'.
I though the loop would take care of it but I guess not.
Here is my code for the loop, what am I doing wrong ?
<cfquery name="qryUpdate_ref_Line_Items" datasource="db">
<cfloop index="i" from="1" to="#form.max_line_Item#">
update TableName
set quantity = '#form.quantity#',
<cfif form.ref_action is "Receive">
po_number = '#form.po_number#',
item = '#form.item#',
part_number = '#form.part_number#'
<cfelseif form.ref_action is "NRC">
tracking_number = '#form.tracking_number#'
<cfelseif form.ref_action is "Other">
instructions = '#form.instructions#'
</cfif>
where ref_number = '#form.ref_number#'
and ref_line_item = '#i#'
</cfloop>
</cfquery>
