Skip to main content
Known Participant
July 2, 2008
Answered

cfloop help

  • July 2, 2008
  • 4 replies
  • 481 views
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>
    This topic has been closed for replies.
    Correct answer dongzky
    You can do this: <cfif "#Evaluate("ref_action_#ref_line_item#")#" is "xxxx">

    4 replies

    dongzkyCorrect answer
    Inspiring
    July 4, 2008
    You can do this: <cfif "#Evaluate("ref_action_#ref_line_item#")#" is "xxxx">
    Inspiring
    July 3, 2008
    what object is your form.quantity? is it a textbox? a list? if it is a textbox and one textbox for each quantity value, maybe you're giving your textboxes the same name? can you check on these things?
    Inspiring
    July 3, 2008
    @ Dan: oh... nice
    Inspiring
    July 3, 2008
    Put the cfquery tag inside the loop.
    Known Participant
    July 3, 2008
    I tried putting the cfquery inside the cfloop and it is still doing the same thing. Instead of one value per column, it is putting in all the values, for example, quantity='100,2,5' and the errro message is regarding and integer problem.

    My loop is incorrect since it does not do one at a time. What else can I do ?
    Inspiring
    July 3, 2008
    quote:

    Originally posted by: Olivia Crazy Horse
    I tried putting the cfquery inside the cfloop and it is still doing the same thing. Instead of one value per column, it is putting in all the values, for example, quantity='100,2,5' and the errro message is regarding and integer problem.

    My loop is incorrect since it does not do one at a time. What else can I do ?

    You are on the right track. You have to use the loop index value in your query though. Something like.

    <cfloop index = "idx">
    <cfquery>
    update sometable
    set somefield = #idx#
    where some_conditions_are_met