Here's how I understand iif:  If the condition is true, return the 2nd
parameter, otherwise return the 3rd.

So in your example, if (didquery and didfind) returns true, the code
will evaluate getCust.#i#.  Otherwise it will evaluate DE("").

iif is basically just a shorter cfif statement, using your example iif,
this would do the same thing:
<cfif didquery and didfind>
        <cfset temp = evaluate("getCust.#i#")>
<cfelse>
        <cfset temp = "">
</cfif>

But that takes a lot more code.

> -----Original Message-----
> From: Josh Nathanson [mailto:[EMAIL PROTECTED] 
> Sent: Friday, July 21, 2006 1:41 PM
> 
> I have some code that loops over a list of fields to cfparam some 
> attributes.  The idea is, if the query (getCust) returns a 
> record, set the 
> attribute to the query.column value;  if no record, set the 
> attribute to 
> null.  After some hacking around I got it to work as desired, 
> but I don't 
> quite understand how.
> 
> <cfset fieldlist = 
> "Customer_ID,FirstName,LastName,Email,Address1,Address2,City,S
> tate,State2,Zip,Country,Phone">
> <cfloop list="#fieldlist#" index="i">
>  <cfset temp = iif(didquery and didfind, "getCust.#i#", DE(""))>
>  <cfparam name="attributes.#i#" default="#temp#">
> </cfloop>
> 
> What I don't get is how iif works.  It seems to do the following:
> - Doesn't evaluate "getCust.#i#" when the page is compiled
> - Assuming the iif conditional evaluates true, when the list 
> is looped, 
> first evaluates just the "#i#" in "getCust.#i#" to return the 
> proper field 
> name, then evaluates the variable "getCust.FirstName" (for 
> example) to 
> return the correct value.  So there is sort of a double 
> evaluation going on.
> 
> Am I understanding iif correctly or does someone have a 
> better explanation 
> as to how it works.  The docs are kind of hard to fathom.

This transmission may contain information that is privileged, confidential 
and/or exempt from disclosure under applicable law. If you are not the intended 
recipient, you are hereby notified that any disclosure, copying, distribution, 
or use of the information contained herein (including any reliance thereon) is 
STRICTLY PROHIBITED. If you received this transmission in error, please 
immediately contact the sender and destroy the material in its entirety, 
whether in electronic or hard copy format. Thank you. A1.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/cf_lists/message.cfm/forumid:4/messageid:247353
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to