• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

updating multiply records

Explorer ,
Jul 03, 2007 Jul 03, 2007

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

433

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2007 Jul 03, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 03, 2007 Jul 03, 2007

Copy link to clipboard

Copied

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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2007 Jul 03, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2007 Jul 03, 2007

Copy link to clipboard

Copied

OK, I think I have it figured out. Thank you so much for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 03, 2007 Jul 03, 2007

Copy link to clipboard

Copied

LATEST
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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation