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

looping through a struct in the wrong order?

Explorer ,
Oct 17, 2006 Oct 17, 2006
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.
598
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

Contributor , Oct 18, 2006 Oct 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
Translate
Advocate ,
Oct 17, 2006 Oct 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.
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
Contributor ,
Oct 18, 2006 Oct 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
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
Explorer ,
Oct 18, 2006 Oct 18, 2006
LATEST
good thinkin! you the man!
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