Arrays/Structures in CFLOOP

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. Nesting Arrays within arrays.
      How do i nest an array inside another array? something like array(i).aray2(j); Can I do that?
    2. Problem with Structures
      Is there a way to order (sort) them?
    3. 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. ...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139