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

struct/array problem with empty positions

Community Beginner ,
Jun 23, 2012 Jun 23, 2012

Need a little assistance with a struct/array problem please! -----------------------------------------------------------------------------------

Data in question is coming from ONE row in the database.

There are six "fpcomm" cells: fpcomm1,fpcomm2, ... and so on

There are also six "fpord" cells: fpord1, fpord2, ... and so on 

So, I need to display the contents of the fpcomm cells, ordered by the integer in the fpord cells.

My query is "getNEWS". 

The below works great, and sorts the results as I need. 

<cfset allNEWS = StructNew()>

<cfloop from="1" to="6" index="i">    

<cfset oneSTORY = StructNew()>    

<cfset oneSTORY.cellID = "#i#">    

<cfset oneSTORY.ord = "#getNEWS["fpord#i#"][1]#">    

<cfset oneSTORY.cell = "#getNEWS["fpcomm#i#"][1]#">    

<cfset allNEWS[oneSTORY.cell] = oneSTORY>

</cfloop>

<cfset sortedKeys = StructSort(allNEWS, "numeric", "asc", "ord")> 

Here's the problem, maybe fpcomm5 and fpcomm6 are EMPTY (or NULL) on a particular day. REGARDLESS, I still need all six positions in "sortedKeys" returned. 

Let's say for the moment that fpcomm5 and fpcomm6 cells are empty. If I do a dump of "sortedKeys", I'll get:

1   Item One

2   Item Two

3   Something Else

4   Even Something Else

5   [empty string] 

It INCLUDES the first emtpy row (fpcomm5), but NOT fpcomm6, which looks exactly like fpcomm5 in the database. If fpcomm4, 5, and 6 are empty, it will include fpcomm4, but not 5 and 6.

Weird - it only include the FIRST empty element....

I need the array to always include all six elements. [empty string] is exactly what I need - but I need ALL of them. 

Suggestions?

585
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
Community Beginner ,
Jun 23, 2012 Jun 23, 2012
LATEST

Actually, while playing with it more, if "fpcomm1" and "fpcomm2" contain the same value like "Bob has News", it's only going to display the FIRST one. So duplicate values seem the issue. If three cells contain [empty string], it's only going to include the first one...

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