View Single Post
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