Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > ColdFusion

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-21-2012, 08:02 PM   PM User | #1
mont2105
New to the CF scene

 
Join Date: May 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
mont2105 is an unknown quantity at this point
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!
mont2105 is offline   Reply With Quote
Old 05-22-2012, 03:08 AM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 05-22-2012, 10:05 AM   PM User | #3
mont2105
New to the CF scene

 
Join Date: May 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
mont2105 is an unknown quantity at this point
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
mont2105 is offline   Reply With Quote
Reply

Bookmarks

Tags
array, coldfusion

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:06 AM.


Advertisement
Log in to turn off these ads.