Skip to main content
Participant
June 23, 2012
Question

struct/array problem with empty positions

  • June 23, 2012
  • 1 reply
  • 620 views

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?

    This topic has been closed for replies.

    1 reply

    Participant
    June 23, 2012

    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...