Skip to main content
Known Participant
October 28, 2008
Question

cfloop list question

  • October 28, 2008
  • 3 replies
  • 375 views
I have a form that cfoutputs something like this, with the record number hidden
code PO number record no
========================
123 PO999 1
123 PO000 2
111 PO123 3

I want to be able to update the code and PO number columns, for each row. When I submit and do a cfoutput to look at the data, the code is comma deliminted list, 123,123,111 and so is the po, PO999, PO000,PO123.

So I use a cfloop list="#form.code#" index="i">
set code = '#i#'
where poNumber = '#form.POnumber#"
and recordNo = '#form.recordNO#'

But what is happending is that when I cfoutput the record number to look at the data, it is also in list, and if I try to use recordNO in (#form.recordNO#), it updates all the records to the same values, not the ones that I changed them to.

I tried to break them up by attempting an update of the code first, then the Po number, uisng the loops, but it still does not work.

I am totally confused now beuase there are mulitple lisrts involved.

What do I need to do to update one or more columns, per row ?

Thanks for any advice.
    This topic has been closed for replies.

    3 replies

    Inspiring
    October 28, 2008
    Hopefully your list of codes and record numbers are in synch. If so, try something like this:

    <cfloop from = 1 to = listlen(form.code) index = "i">
    <cfquery>
    update myTable
    set code = '#listgetat(form.code, i)'
    where gfmRdn = '#form.gfmRdn#'
    and recordNumber = #listgetat(form.recordnumber, i)#
    BKBK
    Community Expert
    Community Expert
    October 28, 2008
    It's indeed confusing. As a rule, you shouldn't be storing lists in the database.

    If you're getting a list after submitting a form, then there are likely multiple fields in the form that have the same name. Could you show us the code for the form?



    Inspiring
    October 28, 2008
    Do you have a code sample that you're using?

    "Olivia Crazy Horse" <webforumsuser@macromedia.com> wrote in message
    news:ge5ls4$660$1@forums.macromedia.com...
    >I have a form that cfoutputs something like this, with the record number
    >hidden
    > code PO number record no
    > ========================
    > 123 PO999 1
    > 123 PO000 2
    > 111 PO123 3
    >
    > I want to be able to update the code and PO number columns, for each row.
    > When
    > I submit and do a cfoutput to look at the data, the code is comma
    > deliminted
    > list, 123,123,111 and so is the po, PO999, PO000,PO123.
    >
    > So I use a cfloop list="#form.code#" index="i">
    > set code = '#i#'
    > where poNumber = '#form.POnumber#"
    > and recordNo = '#form.recordNO#'
    >
    > But what is happending is that when I cfoutput the record number to look
    > at
    > the data, it is also in list, and if I try to use recordNO in
    > (#form.recordNO#), it updates all the records to the same values, not the
    > ones
    > that I changed them to.
    >
    > I tried to break them up by attempting an update of the code first, then
    > the
    > Po number, uisng the loops, but it still does not work.
    >
    > I am totally confused now beuase there are mulitple lisrts involved.
    >
    > What do I need to do to update one or more columns, per row ?
    >
    > Thanks for any advice.
    >
    >

    Known Participant
    October 28, 2008
    I am trying to use something like this, the form.code is a list, but then so is the form.recordNumber and that is what is blowing up. If I change it to recordNumber in (#form.recordNumber#) it update all values, not just the ones selected.

    <cfloop list="#formCode#" index="i">
    <cfquery name="qryUpdate" datasource="dbName">
    update myTable
    set Code = '#i#'
    where gfmRdn = '#form.gfmRdn#'
    and recordNumber = #form.recordNumber#
    </cfquery>
    </cfloop>