Ask a Question related to Coldfusion Database Access, Design and Development.
-
crux_online #1
Arrays/Structures in CFLOOP
From the code below you can see basically what I am trying to accomplish: to
set up a CFLOOP from an earlier query, an insert some permutation of the
RETRIEVED data into the name of the variable itself.
For example, if the datum retrieved is 'fred', then the name of the variable
would be 'Event.fred' or something similar.
Naturally, I can entertain Array-based (or really, ANY) solutions, but
structures seem more powerful and easier to use in a dynamic environment.
Thanks a lot,
Robert Nicholas
<cfset Event=NewStruct()>
<cfloop query="getEvents">
<cfset Event.[date of the event]=getEvents.EventSchedDate
</cfloop>
crux_online Guest
-
Nesting Arrays within arrays.
How do i nest an array inside another array? something like array(i).aray2(j); Can I do that? -
Problem with Structures
Is there a way to order (sort) them? -
Assigning structures to arrays
Can somebody explain to me why this is happening? I don't get it.... I'm trying to create an array of structures using the code below. ... -
Shopping cart with arrays and structures
Hello all- I'm only on line 3 of building a shopping cart, and it already has issues. I'm following online instructions on how to build a shopping... -
structures vs classes
Hi! I'd like to know is what are the prons and cons of using structures (data types declared as struct or structure ) as against classes when... -
Dan Bracuk #2
Re: Arrays/Structures in CFLOOP
You have to specify the rownumber, like this:
<cfset Event.[date of the event]=getEvents.EventSchedDate[currentrow]>
Originally posted by: crux_online
From the code below you can see basically what I am trying to accomplish: to
set up a CFLOOP from an earlier query, an insert some permutation of the
RETRIEVED data into the name of the variable itself.
For example, if the datum retrieved is 'fred', then the name of the variable
would be 'Event.fred' or something similar.
Naturally, I can entertain Array-based (or really, ANY) solutions, but
structures seem more powerful and easier to use in a dynamic environment.
Thanks a lot,
Robert Nicholas
Dan Bracuk Guest
-
mxstu #3
Re: Arrays/Structures in CFLOOP
crux_online,
I'm assuming your attached code is just psuedo-code. You already understand
the basic idea. Exactly what problem are you are having?
<!--- where ... "EventPerson" is column containing "Fred", etc.. --->
<cfset Event = StructNew()>
<cfloop query="getEvents">
<cfset Event[EventPerson] = getEvents.EventSchedDate>
</cfloop>
<cfdump var="#Event#">
mxstu Guest
-
crux_online #4
Re: Arrays/Structures in CFLOOP
Your assumptions are sound: it was pseudocode.
I did actually get it to work with some tinkering and it seems pretty well
preamlined. I simply remembered a little queary parameter called #CurrentRow#
and the light came on, so to speak.
I'm attaching the final code. Here's a quick run-down of the purpose of the
page:
This page creates a dynamic calendar whose dates are calculated based on the
current day (highlighted), whose fisrt week is always the present week (and
always displays a 5-week span), and whose event contents are retrieved from a
database and displayed by an icon (icon for a uniform and icon for the type of
event). Description of the event are then listed below the calendar.
Seems to be working wonderfully now. Now that I have decent functionality,
eye candy ensues.
Thanks,
Robert Nicholas
<cfloop query="getEvents">
<cfset Events[currentrow] = getEvents.EventSchedDate[currentrow]>
<cfset ToolTip[currentrow] = getEvents.EventToolTip[currentrow]>
<cfset Time[currentrow] = getEvents.EventStartTime[currentrow]>
<cfset Desc[currentrow] = getEvents.EventDesc[currentrow]>
<!--- Assign the proper uniform to the 'iconUOD' variable.
This variable with be used wherever the icon for the
Uniform of the Day is invoked. --->
<cfswitch expression="#LCase(getEvents.EventUOD)#">
<cfcase value="bdu"><cfset iconUOD[currentrow]="bdu"></cfcase>
<cfcase value="class a"><cfset iconUOD[currentrow]="a"></cfcase>
<cfcase value="class b"><cfset iconUOD[currentrow]="b"></cfcase>
<cfcase value="pt"><cfset iconUOD[currentrow]="pt"></cfcase>
<cfcase value="civilian casual"><cfset iconUOD[currentrow]="civ"></cfcase>
<cfcase value="business casual"><cfset iconUOD[currentrow]="biz"></cfcase>
</cfswitch>
<!--- Assign the proper icon for the day's events. --->
<cfswitch expression="#LCase(getEvents.EventType)#">
<cfcase value="regular meeting"><cfset iconType[currentrow]="reg"></cfcase>
<cfcase value="field trip"><cfset iconType[currentrow]="trip"></cfcase>
<cfcase value="award ceremony"><cfset iconType[currentrow]="award"></cfcase>
<cfcase value="promotion"><cfset iconType[currentrow]="promo"></cfcase>
<cfcase value="competition"><cfset iconType[currentrow]="comp"></cfcase>
<cfcase value="test"><cfset iconType[currentrow]="test"></cfcase>
<cfcase value="sar/cpr/fa"><cfset iconType[currentrow]="sar"></cfcase>
<cfcase value="powered o-flight"><cfset iconType[currentrow]="pof"></cfcase>
<cfcase value="party/celebration"><cfset
iconType[currentrow]="party"></cfcase>
<cfcase value="physical fitness test"><cfset
iconType[currentrow]="pt"></cfcase>
<cfcase value="glider o-flight"><cfset iconType[currentrow]="gof"></cfcase>
</cfswitch>
</cfloop>
...
<!--- Insert the appropriate icon into the physical calendar.
Hover over the UOD icon for the event's tooltip. --->
<cfif Events[indexEvent] EQ dODBCCurrentDay>
<img src="/img/cal.uod.#iconUOD[indexEvent]#.gif" border="0"
title="#Time[indexEvent]#: #ToolTip[indexEvent]#" /></a>
<img src="/img/cal.event.#iconType[indexEvent]#.gif" border="0"
title="#Time[indexEvent]#: #ToolTip[indexEvent]#" />
<cfif indexEvent LT getEvents.RecordCount><cfset
indexEvent=indexEvent+1></cfif>
</cfif>
crux_online Guest



Reply With Quote

