Why bother with all the intricate ifs and loops?
<cfif IsDefined("queryname")>
<cfoutput query="queryname">
#foo# - #bar#<br>
</cfoutput>
<cfelse>
<cfloop list="#list#" index="ii">
#ii#<br>
</cfloop>
</cfif>
Or
<cfif IsDefined("queryname")>
<cfset list = ValueList(queryname.columnname)>
</cfif>
<cfloop list="#list#" index="ii">
#ii#<br>
</cfloop>
Of course if you have more than one column called in your query you'll have
a problem with that.
--K
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 17, 2001 6:34 PM
To: CF-Talk
Subject: RE: Conditional loops
I think it would be possible, like
<cfset mycounter = 1>
<cfloop condition="(isdefined("queryname") and mycounter LTE
queryname.recordcount) OR (mycounter LTE listlen(listname)">
<cfoutput>
<cfif isdefined("queryname")>
#queryname.fieldname[mycounter]#
<cfelse>
#listgetat(listname, mycounter)#
</cfif>
<cfset mycounter = mycounter + 1>
</cfloop>
but it might be easier to change the query to a list (ValueList function) or
the list to a query
(http://devex.allaire.com/developer/gallery/info.cfm?ID=CA3471A5-2830-11D4-A
A9700508B94F380&method=Full - custom tag) so you don't have to keep figuring
out what syntax you need.
-----Original Message-----
From: Ruslan Sivak [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 17, 2001 10:06 AM
To: CF-Talk
Subject: RE: Conditional loops
I guess I should've been more clear about what I want to do.
<CFIF isDefined("queryname")>
<CFLOOP query="Queryname">
<CFELSE>
<CFLOOP index="x" list="listname">
</CFIF>
I have gotten a suggestion to rewrite it as
<CFIF isDefined("queryname")>
<CFSET count=queryname.recordcount>
<CFELSE>
<CFSET count=#ListLen(listname)#>
</CFIF>
<CFLOOP from="0" to="#count#">
</cfloop>
-----Original Message-----
From: Dylan Bromby [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 16, 2001 9:20 PM
To: CF-Talk
Subject: RE: Conditional loops
why don't you just use the CONDITION attribute of CFLOOP?
-----Original Message-----
From: Bud [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 16, 2001 4:59 PM
To: CF-Talk
Subject: Re: Conditional loops
On 1/16/01, Ruslan Sivak penned:
>Is there a way to have conditional loops such as
>
><CFIF something>
> <CFLOOP parameters1>
><CFELSE>
> <CFLOOP parameters2>
></CFIF>
>
> </CFLOOP>
Nope. You'll have to put the opening and closing loop tags either
both inside each cfif, cfelse block, or put them outside the entire
cfif.
<CFIF this IS "that">
<cfloop query="example1">
#variable#
</cfloop>
<CFELSE>
<cfloop query="example2">
#variable#
</cfloop>
</CFIF>
Or
<cfloop query="example1">
<CFIF this IS "that">
#variable1#
<CFELSE>
#variable2#
</CFIF>
</cfloop>
--
Bud Schneehagen - Tropical Web Creations
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists