Be careful using cfquery inside cfloop....

If the array has 500 entries, that's 500 different queries that CF has to compile and execute... (although not as bad when using cfqueryparam I presume).  Probably a better idea to use subselects or use SELECT..... WHERE Field IN ( ... list ... ) as Spike suggested.  Better to have the DB do all the work than have to query it a few billion times :o)


Vaughan.



Andrew Muller <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]

23/06/2003 05:59 PM

Please respond to
"CFAussie Mailing List" <[EMAIL PROTECTED]>

To
"CFAussie Mailing List" <[EMAIL PROTECTED]>
cc
Subject
[cfaussie] Re: Loops n Queries n Arrays





Matt

Are you trying to loop over the array and query the db based on the
current id from the iteration, shouldn't your code then be:

<cfloop from="1" to="#arraylen(custOpsShout_pageID)#" index="i">
 <cfquery name="getShoutStories" DATASOURCE="#Application.DSN#">
  SELECT *
  FROM #Application.tablePrefix#TABLESTORY
  WHERE STATUS ='1'
  AND PAGEID = '#custOpsShout_pageID[i]#'
  AND STORYORDER = '0'                
 </cfquery>
</cfloop>

or are you trying to do something different?

Andrew


Hickman, Matt wrote:

> <!--- let's grab the story from each of the pageID's in the array above --->
>
> <cfquery name="getShoutStories" DATASOURCE="#Application.DSN#">
>                  SELECT *
>                  FROM #Application.tablePrefix#TABLESTORY
>                  WHERE STATUS ='1'  
>                  AND PAGEID = '(<cfloop from="1" to="#arraylen(custOpsShout_pageID)#"
> index="i">#custOpsShout_pageID#</cfloop>)'
>                  AND STORYORDER = '0'                
> </cfquery>


--
Andrew Muller
Senior Macromedia Certified Instructor - ColdFusion, Flash
Certified Advanced Macromedia ColdFusion Developer - CF5, CFMX
Certified Macromedia Flash Developer - FL5, FMX

Daemon Internet Consultants
[EMAIL PROTECTED]
http://www.daemon.com.au/training
T:61 2 9380 4162
F:61 2 9380 4204
17 Roslyn Gardens
Elizabeth Bay NSW 2011 AUSTRALIA

Daemon: Serious Web Development


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MX Downunder AsiaPac DevCon - http://mxdu.com/

****************************************************************************
If this communication is not intended for you and you are not an authorised
recipient of this email you are prohibited by law from dealing with or
relying on the email or any file attachments. This prohibition includes
reading, printing, copying, re-transmitting, disseminating, storing or in
any other way dealing or acting in reliance on the information. If you
have received this email in error, we request you contact ABN AMRO Morgans
Limited immediately by returning the email to [EMAIL PROTECTED]
and destroy the original. We will refund any reasonable costs associated
with notifying ABN AMRO Morgans. This email is confidential and may contain
privileged client information. ABN AMRO Morgans has taken reasonable steps
to ensure the accuracy and integrity of all its communications, including
electronic communications, but accepts no liability for materials
transmitted. Materials may also be transmitted without the knowledge of ABN
AMRO Morgans. ABN AMRO Morgans Limited its directors and employees do not
accept liability for the results of any actions taken or not on the basis
of the information in this report. ABN AMRO Morgans Limited and its
associates hold or may hold securities in the companies/trusts mentioned
herein. Any recommendation is made on the basis of our research of the
investment and may not suit the specific requirements of clients.
Assessments of suitability to an individual's portfolio can only be made
after an examination of the particular client's investments, financial
circumstances and requirements.
****************************************************************************
--- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MX Downunder AsiaPac DevCon - http://mxdu.com/

Reply via email to