dynamic query with x.recordcount output
I have a query that gets Distinct States listed in a Sponsor table
<cfquery name="statecount" datasource="#db#">
SELECT DISTINCT STATE FROM tbl_sponsors
WHERE SalesRep = "#form.user#" or Manager = "#form.user#"
</cfquery>
I then loop through the results with this:
<cfloop from="1" to="#statecount.RecordCount#" index="i">
The results are: WA and OR
Inside the loop I create an array for:
<cfset getTotals = ArrayNew(1)>
<cfset ArrayAppend(getTotals, "getTotals#statecount.State#")> This sets "getTotalsWA" and "getTotalsOR" correlating to each loop.
I use the "getTotals" variable to name my query:
<cfquery name="#getTotals[1]#" datasource="#mydatasource#>
I run into a problem when trying to call the RecordCount of the "getTotals[1]" result - #getTotals[1].RecordCount#.
I get the error:
You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members
My logic makes sense to me, but obviously is wrong. How can I adjust it to work?
