Solved

cfoutput cfloop syntax question

Posted on 2010-08-16
4
464 Views
Last Modified: 2012-05-10
Can a cfquery tag be used within a cfoutput tag as shown in the code attached?

If so what is the difference between cfloop instead of cfoutput in the code?



<cfoutput query="GetOrder_id">
			<cfquery name="OrderNotes_ins" datasource="#ARGUMENTS.default_ds#">
				insert into OrderNotes (order_id,ordernote,csr_id)
				values (<cfqueryparam cfsqltype="cf_sql_integer" value="#order_ID#">,'Refund was sent by check',54)
			</cfquery>
		</cfoutput>

Open in new window

0
Comment
Question by:onaled777
  • 2
  • 2
4 Comments
 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 500 total points
Comment Utility
<CFOUTPUT>
mainly use for printing values of variables.

Plus if use query with cfoutput
<CFOUTPUT QUERY="">

then u have advantage of grouping.
0
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 500 total points
Comment Utility
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
As Brichsoft said, yes you are technically allowed to use a cfquery within a cfoutput. However, since the code doesn't display/output any information to the screen, you don't need a cfoutput. Use a cfloop instead.  

BUT .... having said that, I suspect you may not need a loop at all. If the order id's are stored in another table, the values could be transferred in a single statement:

INSERT INTO OrderNotes (order_id,ordernote,csr_id)
SELECT Order_ID, 'Refund was sent by check',54
FROM    YouOrderTable
WHERE  Order_ID  IN
(
<cfqueryparam value="#listOfOrderIDs#" cfsqltype="cf_sql_integer" list="true">
)



0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
It's not clear what your "real" question is .. ?  But performance wise an insert/select typically gives better performance than *both* of those options (cfloop and cfoutput).  Generally, looping should be avoided whenever possible. Not to mention the fact that looping with separate queries usually requires CFTRANSACTION to ensure data integrity. That isn't being used in the code posted.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

16 Experts available now in Live!

Get 1:1 Help Now