Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

**repost**adding <cfloop> contents to a structure key

New Here ,
May 22, 2008 May 22, 2008
Another question in regards to an earlier post with the same name that Mr. Bracuk helped me with. Relevant information again.
I am trying create a structure which contains all the dates of a particular event inside of its elements. A visual representation would look like: EventID:Day1:2008-02-01
Day2:2008-02-02
Day3:2008-02-03.
My query:
<CFQUERY datasource="#sDSN#" name="qEvents">
SELECT event_id,
event_startdate,
event_enddate
from hs_event
</CFQUERY>

My code:
<!--- 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.--->
<cfset ObjEvents = structNew()>
<CFOUTPUT>
<CFLOOP query="qEvents">
<CFSET ObjEvents[currentrow] = qEvents.event_id>

<cfset ThisDate = event_startdate[currentrow]>
<cfset nCounter = 1>
<CFLOOP condition="ThisDate LTE event_enddate[currentrow]">

<CFSET nCounter = nCounter + 1>
<CFSET ThisDate = DateAdd("d", 1, ThisDate)>

</CFLOOP>

</CFLOOP>
</CFOUTPUT>

Mr. Bracuk got me this far. But, I am not at all familiar with the CFSCRIPT tag, and only slightly familiar with the nature of structures <very, very new to programming>. I am assuming from my reading that I need to nest an EventsID structure inside the ObjEvents structure that I have created, and from there, elements that have named value pairs of Day1 = ActualDay. I truly appreciate your help! Dan
TOPICS
Getting started
269
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 22, 2008 May 22, 2008
This was my previous suggestion.
<cfloop query = "qEvents">
<cfscript>
objEvents.#currentrow# = eventid[currentrow];
ThisDate = event_startdate[current_row];
ctr = 1;
while (ThisDate lte event_enddate[currentrow]) {
objEvents.#currentrow#.date#ctr# = ThisDate;
ctr = ctr + 1;
ThisDate = DateAdd("d", 1, ThisDate);
}


This line,
objEvents.#currentrow# = eventid[currentrow];
equates to this line,
<CFSET ObjEvents[currentrow] = qEvents.event_id>
and both are probably wrong. Mine might be wrong bec...
Translate
LEGEND ,
May 22, 2008 May 22, 2008
This was my previous suggestion.
<cfloop query = "qEvents">
<cfscript>
objEvents.#currentrow# = eventid[currentrow];
ThisDate = event_startdate[current_row];
ctr = 1;
while (ThisDate lte event_enddate[currentrow]) {
objEvents.#currentrow#.date#ctr# = ThisDate;
ctr = ctr + 1;
ThisDate = DateAdd("d", 1, ThisDate);
}


This line,
objEvents.#currentrow# = eventid[currentrow];
equates to this line,
<CFSET ObjEvents[currentrow] = qEvents.event_id>
and both are probably wrong. Mine might be wrong because it would start a variable name with a number, and yours has array notation for a structure instead of dot notation. Try this:
<CFSET ObjEvents.Row#currentrow# = qEvents.event_id[currentrow]>.
That should give you things like
ObjEvents.Row1=123
ObjEvents.Row2=456, etc

In your inner loop, where I suggested this:
objEvents.#currentrow#.date#ctr# = ThisDate;
you want
<cfset objEvent.Row#currentrow#.date#nCounter# = ThisDate>
That should give you things like
objEvent.Row1.date1 = 2008-01-01
objEvent.Row1.date2 = 2008-01-02
etc

Do it piecemeal and look at your results with <cfdump var="#objEvent#">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2008 May 23, 2008
LATEST
Answer worked as explained. I can now access each date according to element name. Thank you for your suggestion. It helped me. dan
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources