Solved

create UPDATE query with CFLOOP

Posted on 2003-11-18
2
635 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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