loop over srray in structure?

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default loop over srray in structure?

    Greetings - help would be greatly appreciated! I have a query that pulls
    multiple id's for multiple users. I am putting the id's in an array in
    structures for each user along with their email address and company name. I
    then have another query pulling data for each id and emailing it to the users
    for each structure. I need to loop over the id's in the array (for each
    structure) in the second query. Is this possible? Am I even going about
    this the easiest/right way??:confused;

    dorothy Guest

  2. Similar Questions and Discussions

    1. Class::Struct - want to access structure within structure
      I want to access a structure within a structure. Below is what I had in mind. Please help. #!/perl/bin/perl use Class::Struct; struct Step...
    2. Can a film loop play once, then loop on the last frame(s)?
      I need a film loop to play once, then loop playback on the last frame so I can keep the LOOP of the film loop set. This will allow the tell commands...
    3. Film loop rollovers working with tell sprite, but only if Loop is checked
      on mouseWithin me cursor 280 tell sprite 40 --the sprite containing the film loop sprite(60).member = member("networkmapsbuttonroll") --swapping...
    4. Urgent: Repeat loop and Film loop clash!
      Hi All, Scenario I have a script running in which the spelling which was typed in by the student is corrected. The alphabets are moved to...
    5. Help with loop inside loop and mysql queries
      Hi List. I cannot see my error: I have relation tables setup. main id entity_name main_type etc etc date_in 1 test type1 x y 2003-06-02...
  3. #2

    Default Re: loop over array in structure?

    Hi Dorothy, can we see some code to get a better handle on what you need to do?
    Is the problem that you need to loop through the array of IDs within the
    <cfmail> tag? It would be helpful to see the code and where you are stuck.

    cf scooter Guest

  4. #3

    Default Re: loop over array in structure?

    I need to loop throught the id's in the second query. The loop in the cfmail
    is working but it craps out after the first user when I loop through a list
    (commented out) - and I get: Error Occurred While Processing Request You
    have attempted to dereference a scalar variable of type class java.lang.Integer
    as a structure with members this way........ Code:
    --------------------------------------------------------------------------------
    ----------------------------------------- <cfquery name='contentNOTICE'
    datasource='#application.ds#' dbtype='ODBC'> SELECT
    ..................................... FROM ................. WHERE
    ........................ ORDER BY user.countryid, user.user_id,
    contents.contentid </cfquery> <cfoutput> <cfset user_email =
    '#contentNOTICE.email#;'> #user_email# </cfoutput> <cfoutput
    query='contentNOTICE' group='countryid'> #Country# <hr> <cfoutput
    group='user_id'> <cfset user = StructNew()> <cfset user.ContentType =
    'Country'> <cfset user.TypeData = #contentNOTICE.country#> <cfset user.email =
    #contentNOTICE.email#> <cfoutput><cfset
    contentList='#contentNOTICE.contentid#'></cfoutput> <!--- start array --->
    <CFSET contents=ArrayNew(1)> <CFSET contents[1] = '0001'> <cfloop
    index='contentid' list='contentList' delimiters=','>
    <CFOUTPUT>#ArrayAppend(contents, '#contentid#')#</CFOUTPUT> </CFLOOP>
    <cfset user.contentlist = contents> <CFSET myList=ArrayToList(contents, ',')>
    <cfdump var=#user#> <cfquery name='getContentcontent'
    datasource='#application.ds#' maxrows=25 dbtype='ODBC'> SELECT ...........
    FROM..................... <!--- <cfloop list='#myList#' index='listItem'>
    <Cfif #listFirst(mylist)# EQ #listItem#>AND (<cfelse>OR </cfif>
    (contents.contentID = #listItem#) </cfloop> ) ---> <cfloop index='contentid'
    from='1' to='#arraylen(contents)#'> <Cfif #contents[1]# EQ
    #contentlist[contentid]#>AND (<cfelse>OR </cfif> (contents.contentID =
    #contents[contentid]#) </cfloop> ) ORDER BY contents.contentcountryid
    ASC</cfquery> <cfmail group='countryid' to='#user.email#' from='admin'
    subject='#user.ContentType#' type='HTML' groupcasesensitive='Yes'> <cfloop
    query='getContentcontent' startrow='1'
    endrow='#getContentcontent.recordcount#'> #contentid#<br> </cfloop>
    </cfmail> </cfoutput> </cfoutput>

    dorothy Guest

  5. #4

    Default Re: loop over array in structure?

    I'm a little confused by this line: <cfoutput><cfset
    contentList='#contentNOTICE.contentid#'></cfoutput> Because it is an inner
    loop, I'm assuming that you have multiple records with different ContentIDs (as
    opposed to a single record in your table that has a list of IDs) ... so,
    shouldn't you be using the ListAppend() function here? Like this... <cfset
    ContentList = ''> <cfoutput><cfset contentList =
    ListAppend(ContentList,contentNOTICE.contentid)></cfoutput> Also, when you are
    looping through this list, you need to use #'s around the list name, like
    this... <cfloop index='contentid' list='#contentList#' delimiters=','> Hope
    that helps, scooter

    cf scooter Guest

  6. #5

    Default Re: loop over array in structure?

    The commented code

    contents.contentID = #listItem# iswrong you previously created contents an Array so you would set a value as below


    contents[listindex] = #listItem#

    Pete Thomas Guest

  7. #6

    Default Re: loop over array in structure?

    That line - <cfoutput><cfset
    contentList='#contentNOTICE.contentid#'></cfoutput> works fine. I ended up
    setting a list because I couldn't loop through the array in the structure. It
    pulls everything I need for one user then on the second time through the loop I
    get nothing. So..... I went back to trying to loop through the array of id's
    in the structure and got the other error: Error Occurred While Processing
    Request You have attempted to dereference a scalar variable of type class
    java.lang.Integer as a structure with members

    dorothy Guest

  8. #7

    Default Re: loop over array in structure?

    There are different arrays in different structures for each user - I tried to
    loop through them on the second query and get an error. Is this the correct
    way to loop through an array in a structure??? <cfloop index='contentid'
    from='1' to='#arraylen(contents)#'> <Cfif #contents[1]# EQ
    #contentlist[contentid]#>AND (<cfelse>OR </cfif> (contents.contentID =
    #contents[contentid]#) </cfloop> )

    dorothy Guest

  9. #8

    Default Re: loop over array in structure?

    There are different arrays in different structures for each user - I tried to
    loop through them on the second query and get an error. Is this the correct
    way to loop through an array in a structure??? <cfloop index='contentid'
    from='1' to='#arraylen(contents)#'> <Cfif #contents[1]# EQ
    #contentlist[contentid]#>AND (<cfelse>OR </cfif> (contents.contentID =
    #contents[contentid]#) </cfloop> ) (contents.contentID =
    #contents[contentid]#) this line is incorrect u are referencing an array as a
    structure

    Pete Thomas Guest

  10. #9

    Default Re: loop over array in structure?

    So how do I reference the array in the structure?
    dorothy Guest

  11. #10

    Default Re: loop over array in structure?

    so a you have an array with key of 'myarray' in structure mystruct.

    it would be mystruct.myarray[index] index being numeric
    Pete Thomas Guest

  12. #11

    Default Re: loop over array in structure?

    Ok - tried that: <cfloop index='contentid' from='1'
    to='#arraylen(contentlist)#'> <Cfif #user.contentlist[1]# EQ
    #user.contentlist[contentid]#>AND (<cfelse>OR </cfif> (contents.contentID =
    #contents[contentid]#) </cfloop> ) and got this: Object of type class
    java.lang.Integer cannot be used as an array What am I doing wrong here???

    dorothy Guest

  13. #12

    Default Re: loop over array in structure?


    <cfloop from='1' to='#ArrayLen(user.contentlist)#' index='i'>
    #user.contentlist#<br>
    </cfloop>
    dorothy 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