Solved

create UPDATE query with CFLOOP

Posted on 2003-11-18
2
633 Views
Last Modified: 2013-12-24
I would like to create a query based on CFLOOP.  I need to update a undetermined number of numerically-named fields.  After the loop is processed, I am looking for the following example to be what the MySQL server gets:

<cfquery datasource="DSN">
UPDATE myTable
SET Field = 'Form.Field1',
       Field = 'Form.Field2',
       Field = 'Form.Field3',
WHERE x = y
</cfquery>

I was thinking that the code could be something like this:

<cfquery datasource="DSN">
UPDATE myTable
SET dummy=0
<cfloop from="1" to="#NumberOfLoops#" index="i">
       ,Field = '#Form.Field#i##'
</cfloop>
WHERE x = y
</cfquery>

However, I don't know if you can nest variables like this.  How could I accomplish what I'm describing?
0
Comment
Question by:theamzngq
2 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 100 total points
ID: 9771877
Try this.

<cfquery datasource="DSN">
UPDATE myTable
SET dummy=0
<cfloop from="1" to="#NumberOfLoops#" index="i">
       ,Field = '#evaluate("Form.Field"  &  i)#'
</cfloop>
WHERE x = y
</cfquery>
0
 
LVL 2

Author Comment

by:theamzngq
ID: 9774880
That did it, thank you for expanding my knowledge...
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question