Question
adding <cfloop> contents to a structure key
I am trying to loop through the contents of a query and add
the values created from the loop to a structure. Here is my query:
<CFQUERY datasource="#sDSN#" name="qEvents">
SELECT event_id,
event_startdate,
event_enddate
from hs_event
</CFQUERY>
Here is my the code related to my loop.
<!---Create an event structure structure to hold the dates of the events.--->
<CFSET objEvents = StructNew()>
<!--- Populate the event structure by running a loop that will go from the startdate listed in the event_startdate column and go to the hs_event_enddate column, incrementing by 1 for each "day" between these 2 dates.--->
<CFLOOP query="qEvents">
<CFSET intDateFrom = Fix(qEvents.event_startdate)>
<CFSET intDateTo = Fix(qEvents.event_enddate)>
<CFLOOP index="intDate" from="#Max(ThisMonthYear, intDateFrom)#" to="#Min(Days, intDateTo)#" step="1">
<CFSET objEvents[intDate] = qEvents.event_id>
</CFLOOP>
</CFLOOP>
<cfoutput><cfdump var="#objevents#"></cfoutput>
When I run this, it does not throw an error. However, it also does not fill the structure with the event_id values. The structure remains empty. What am I doing wrong? Thanks so much in advance! Dan
<CFQUERY datasource="#sDSN#" name="qEvents">
SELECT event_id,
event_startdate,
event_enddate
from hs_event
</CFQUERY>
Here is my the code related to my loop.
<!---Create an event structure structure to hold the dates of the events.--->
<CFSET objEvents = StructNew()>
<!--- Populate the event structure by running a loop that will go from the startdate listed in the event_startdate column and go to the hs_event_enddate column, incrementing by 1 for each "day" between these 2 dates.--->
<CFLOOP query="qEvents">
<CFSET intDateFrom = Fix(qEvents.event_startdate)>
<CFSET intDateTo = Fix(qEvents.event_enddate)>
<CFLOOP index="intDate" from="#Max(ThisMonthYear, intDateFrom)#" to="#Min(Days, intDateTo)#" step="1">
<CFSET objEvents[intDate] = qEvents.event_id>
</CFLOOP>
</CFLOOP>
<cfoutput><cfdump var="#objevents#"></cfoutput>
When I run this, it does not throw an error. However, it also does not fill the structure with the event_id values. The structure remains empty. What am I doing wrong? Thanks so much in advance! Dan