Funny problem with DTML, please help!
Hi guys, I hope someone can help me with this one, because it's almost driving me crazy :-) The following code fails with an error for count_yes: <!--#comment--> Calculate the vote percentage <!--#/comment-> <!--#call "REQUEST.set('count_yes', 0)"--> <!--#call "REQUEST.set('count_no', 0)"--> <!--#call "REQUEST.set('count_all', 0)"--> <!--#in sql_distinct_votes--> <!--#if "cnt == 1"--> <!--#if "answer == 'Y'"--> <!--#call "REQUEST.set('count_yes', REQUEST['count_yes']+cnt)"--> <!--#/if--> <!--#if "answer == 'N'"--> <!--#call "REQUEST.set('count_no', REQUEST['count_no']+cnt)"--> <!--#/if--> <!--#call "REQUEST.set('count_all', REQUEST['count_all']+cnt)"--> <!--#/if--> <!--#/in--> <!--#comment--> Now display the results <!--#/comment--> <h2> Total : <!--#var "REQUEST['count_all']"--> votes</h2> <ul> <li>Yes : <!--#var "REQUEST['count_yes']"--> votes (<!--#var "_.round(((REQUEST['count_yes']+0.0)/REQUEST['count_all'])*100,1)"-->%)</li> <li>No : <!--#var "REQUEST['count_no']"--> votes (<!--#var "_.round(((REQUEST['count_no']+0.0)/REQUEST['count_all'])*100,1)"-->%)</li> </ul> When I change <!--#call "REQUEST.set('count_yes', REQUEST['count_yes']+cnt)"--> to <!--#call "REQUEST.set('count_yes', cnt)"--> it works as expected, no errors, but that's not what I want :-( I've tried, superstitiously, to change count_yes to several other things, but no luck. It always gives me an error for the vairable I substitute for count_yes. The strangest thing is that the same code works for count_no and count_all ?!? Any ideas?
In article <m3hfqbvrbg.fsf@ns1.aster.net>, <pan@aster.net> wrote:
Hi guys,
I hope someone can help me with this one, because it's almost driving me crazy :-)
This isn't really an answer to your question, but why not let the SQL server do the counting for you? Something like SELECT COUNT(*) AS yes_num FROM votes WHERE answer = 'Y' Will get you the number without having to examine each record in DTML.
participants (2)
-
pan@aster.net -
tsarna@endicor.com