Solved

create UPDATE query with CFLOOP

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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
CGI takes almost 2 minutes to load using thttpd 20 41
Communicating between two servers 5 85
htaccess restrict subdomain 4 70
WEB Farm 6 25
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now