Skip to main content
Inspiring
October 17, 2006
Answered

looping through a struct in the wrong order?

  • October 17, 2006
  • 2 replies
  • 574 views
the attached code, sets up a struct containing info about 5 rss feeds. then i loop through the struct and call a CFC which reads the feeds, and i output each feed to the screen.

problem is that when i create the struct i have the keys in the following order:
1. digg.com
2. netflix.com
3. phpfreaks tutorials
4. phpfreaks articles
5. porkchopsandwich.com

but they are output in this order:
1.digg.com
2. phpfreaks articles
3. phpfreaks tutorials
4.porkchopsandwich.com
5.netflix

i cant figure out why? if i dump the struct, the keys are displayed in the correct order. i dont get it. any help would be appreciated.
    This topic has been closed for replies.
    Correct answer CRidgway
    Change your cfloop

    <cfloop from="1" to="#StructCount(feeds)#" index="feed">

    Since you have your structure defined with a number, just reference that and you are fine.

    CR

    2 replies

    CRidgwayCorrect answer
    Inspiring
    October 18, 2006
    Change your cfloop

    <cfloop from="1" to="#StructCount(feeds)#" index="feed">

    Since you have your structure defined with a number, just reference that and you are fine.

    CR
    bdee2Author
    Inspiring
    October 18, 2006
    good thinkin! you the man!
    Participating Frequently
    October 17, 2006
    A struct is an unordered data structure. If you need a strict ordering, you need to manage it manually or use an ordered data structure.

    It looks like you could use an array of structures. The array would ensure your ordering for you.