5 Replies Latest reply on Jul 3, 2007 12:00 PM by Newsgroup_User

    updating multiply records

    mkt
      I have a form that queries and retrieves up to 7 records that can match the criteria. I display the 7 records and add data to the record. When the record is submitted I transmit the record id for each of the records as a hidden field. When I look at the debug information I can see all the data did some over for every record. My problem is how to update each of the records. I used a loop but I get errors. See attached code for loop code and error messages. I have searched the forum and can not find an anser to this so any assistance would be appreciated.
      Thanks
        • 1. Re: updating multiply records
          mkt Level 1
          OK, I figured out my loop error - I replace my where form.rec_id with 'i' and it worked except now, it placed all the data in each record. Such as record id 1 field csd_focus has test1, test2, test3, test4 verses just test1. Any suggestions?
          • 2. Re: updating multiply records
            Level 7
            mkt wrote:
            > OK, I figured out my loop error - I replace my where form.rec_id with 'i' and
            > it worked except now, it placed all the data in each record. Such as record id
            > 1 field csd_focus has test1, test2, test3, test4 verses just test1. Any
            > suggestions?
            >

            You are using the same form field name for each instance of the data.
            In HTTP this means the data is returned as a list in the form submit
            request. You could use listGetAt() type functionality to loop over your
            form fields and pull each item out individually, but the HTTP request
            does not guarantee the order of the list, and there is a small chance
            that the record items may not match up.

            What most developers do is dynamically name the form fields so that you
            can tell which ones belong together. When you do this you will get form
            fields like this:

            CSD_FOCUS_1 = test1
            CSD_FOCUS_2 = test2
            CSD_FOCUS_3 = test3
            CSD_FOCUS_4 = test4
            CSD_POSITION_1 = Preferred Vendor
            ect.

            You can now be confident that all the '_1' fields belong to the same
            record. You then can use array notation and string concatenation to
            access the data with a loop.

            <cfloop .... index="i">
            <cfoutput>
            #form['CSD_FOCUES_' & i]# - #form['CSD_POSITION_' & i]# ...
            </cfoutput>
            </cfloop>

            HTH

            Ask away if you need further clarification.


            • 3. Re: updating multiply records
              mkt Level 1
              Thank you. One question, how do I name my fields in the form so the names will be different? Also, I could have 1 record returned or 20. Here is what I have now

              Thanks
              • 4. Re: updating multiply records
                mkt Level 1
                OK, I think I have it figured out. Thank you so much for your help!
                • 5. Re: updating multiply records
                  Level 7
                  How are you looping to create each form field collection?

                  Presuming a query loop.
                  <td><cfinput type="Text" name="csd_focus_#myQuery.currentRow#"
                  required="No"></td>

                  Presuming an index loop with 'i' as the index variable.
                  <td><cfinput type="Text" name="csd_focus_#i#" required="No"></td>

                  Of course the entire loop will need to be inside an output block of some
                  sort.