Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with accessing array

    Hi

    Anyone give me a pointer this issue, its driving me nuts. Using coldfusion9. Here's the code with an 'issue', which I dont know how to resolve:

    <cfset CheckCountry=Compare(#CountryNewsAggregator[arrayRowPointer][1]#,#Country#)>

    The error CF is throwing back at me is:

    Error Occurred While Processing Request
    The element at position 1, of dimension 2, of an array object used as part of an expression, cannot be found.

    It bassically doesnt like [arrayRowPointer]

    If I dump arrayRowPointer out to the page, I get a number that I expect.

    #Country# is from my query result and I've checked its coming back with a string.
    the second dimension, shown as [1] above, is a virtual column where Im storing country names.

    If I change the code to this, hardcoding the rownumber (bold):
    <cfset CheckCountry=Compare(#CountryNewsAggregator[1][1]#,#Country#)>

    CF seems happy. But that's no good for me, I'm in a cfloop and want to iterate through the row numbers in the array.

    It seems like some kind of type conversion isnt working ? anyone have any ideas?

    Thanks!

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I'd have to see all the code before I comment. Are you sure that "arrayRowPointer" is the index of the loop?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    I'd have to see all the code before I comment. Are you sure that "arrayRowPointer" is the index of the loop?
    Hi

    Thanks for reply.

    Here's my code:

    <!--- Declare a new 2d array to store the CR RSS feed query results in to --->
    <cfset CountryNewsAggregator = ArrayNew(2)> <!--- that's a 2 dimensional array --->
    <cfset arrayRowPointer = 1>
    <cfset MatchFound =0>

    <!--- loop through the query results and get the query data into the array --->
    <cfoutput query="GetCRNewFeed">
    <!--- Check if the array is empty, then put in first result from query output --->
    <cfif #ArrayIsEmpty(CountryNewsAggregator[1])# Is True>
    <!--- the array is empty--->
    <cfset #CountryNewsAggregator[1][1]# = #Country#>
    <cfset #CountryNewsAggregator[1][2]# = #CountryLat#>
    <cfset #CountryNewsAggregator[1][3]# = #CountryLong#>
    <cfset #CountryNewsAggregator[1][4]# = #ArticleTitle#>
    <cfset #CountryNewsAggregator[1][5]# = #ArticleSummary#>
    <cfset #CountryNewsAggregator[1][6]# = #ArticlePublishedDate#>
    <cfset #CountryNewsAggregator[1][7]# = #LinkToFullArticle#>
    <cfelse>
    <!--- the array is not empty --->
    </cfif>
    <!---<cfdump var = '#CountryNewsAggregator#'>--->

    <br><b>#arrayRowPointer#</b><br><br><br>

    <!--- now do a search through the array 'Country' column to see if the current Country already exists in the array--->
    <cfloop from="1" to="#ArrayLen(CountryNewsAggregator)#" index="i">
    <cfif #CountryNewsAggregator[arrayRowPointer][1]# Is #Country# >
    <cfset MatchFound = 1>
    <cfbreak>
    <!--- we will append later --->
    <cfelse>
    <cfset MatchFound = 0>
    </cfif>
    </cfloop>



    <!--- DEBUG <cfset MatchFound = 0> --->

    <cfif #MatchFound# Equal '0'>
    <!--- country name not found in array so add details --->
    <cfset #CountryNewsAggregator[arrayRowPointer][1]# = #Country#>
    <cfset #CountryNewsAggregator[arrayRowPointer][2]# = #CountryLat#>
    <cfset #CountryNewsAggregator[arrayRowPointer][3]# = #CountryLong#>
    <cfset #CountryNewsAggregator[arrayRowPointer][4]# = #ArticleTitle#>
    <cfset #CountryNewsAggregator[arrayRowPointer][5]# = #ArticleSummary#>
    <cfset #CountryNewsAggregator[arrayRowPointer][6]# = #ArticlePublishedDate#>
    <cfset #CountryNewsAggregator[arrayRowPointer][7]# = #LinkToFullArticle#>
    <cfelse>
    <!--- looks like the country was found to already exist in the array, so append to it - DO LATER --->
    </cfif>
    --->

    <!--- incrememnt the row pointer, get it on the next row ready for next set of data --->
    <cfset arrayRowPointer = arrayRowPointer+1>
    </cfoutput>


    Explanation:
    I do a query and get a load of results back. In the results, there is a column called 'Country', country can have multiple entries for the same country, e.g. 5 rows all for Germany.

    I want to build a new list in memory using an array, but condense the query results down, e.g. so my new list doesnt contain 5 entries for Germany, but just one.

    So, I'm trying to use cfloop to search the array for the current recordset.country, if the country is already found to exist in the array, I will do some code (not present in above yet), to append to the existing country. If the country IS NOT found by searching through it, I want to add a new entry into the array, therefore dynamically growing the array. Coldfusion doesnt seem to like this code: <cfif #CountryNewsAggregator[arrayRowPointer][1]# Is #Country# >, specifically, it seems to be arrayRowPointer it doesnt like. I think possibly whats going on is that I'm trying to do a <cfif> on an array value that doesnt exist, and its bombing out, but I cant see how to fix.

    I know the above code isnt the most elegant, and it is dev, I just wanted to get something working. I explored the use of ArrayFindNoCase function but this doesnt work on multidimensional arrays (confirmed by Adobe).

    Thanks


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •