Skip to main content
Inspiring
May 12, 2008
Question

3 Q-of-Q's into a loop??

  • May 12, 2008
  • 3 replies
  • 341 views
I was thinking it would be easier to write out something like:

<cfset startpoint=1>
<cfloop list="1,0,-1" index="i" delimiters=",">
<cfquery name="itemCount" dbtype="query">
select count(*) as rCount
from ReviewDisplay
where Rev_Overall='#i#'
</cfquery>
<cfset c_count#startpoint#=#itemCount.rCount#>
<cfset startpoint=startpoint+1>
</cfloop>

But it fails on either:
<cfset c_count#startpoint#=#itemCount.rCount#>

or

will say:
Comparison exception while executing =.
Unsupported Type Comparison Exception: The = operator does not support
comparison between the following types:
Left hand side expression type = "INTEGER".
Right hand side expression type = "STRING".

Or I get a empty string back.......

Why??



    This topic has been closed for replies.

    3 replies

    Inspiring
    May 13, 2008
    I think perhaps you could do with reading the docs on #-usage too...

    http://livedocs.adobe.com/coldfusion/8/htmldocs/Expressions_09.html

    --
    Adam
    Inspiring
    May 13, 2008
    For starters, take the octothorps out of your cfset tag. Next, to see why you are getting an empty string, cfdump your query results each time.

    And read cfSearching's answer. You might need a loop, but it will be after a single query.
    Inspiring
    May 12, 2008
    Steve Grosz wrote:
    I was thinking it would be easier to write out something like:

    Is there a specific reason you think you need a loop? A single query with a group by should give you the counts for each "Rev_Overall". You could then loop over the query as needed.

    SELECT Rev_Overall, count(*) as rCount
    FROM ReviewDisplay
    WHERE Rev_Overall IN
    (
    <cfqueryparam value="1,0,-1" cfsqltype="(column type here)" list="true">
    )
    GROUP BY Rev_Overall


    But it fails on either:
    <cfset c_count#startpoint#=#itemCount.rCount#>


    Use array notation to set a dynamic variables

    <cfset variable["c_count"& someCounterNumber] = "some value">