[thelist] Displaying survey results

Chris Spruck cspruck at mindspring.com
Mon Mar 19 23:04:37 CST 2001


At 10:38 PM 3/19/01 -0500, you wrote:
>On 19 Mar 2001, at 18:36, Minh Lee Goon wrote:
>
> > Here's my question: How do I display that information so that it's
> > understandable? It doesn't have to be graphical, just comprehensive. The
> > crudest method would be to query each column in the results database for
> > every possible option (i.e. four queries per question for each option,
> > using the WHERE clause in my SELECT statement) and then displaying the
> > results using RecordCount.
>
>I fought with this one for a *long* time a couple of years ago. I
>didn't want to get into graphics programming, and when this one
>came to me after a couple of weeks, I was embarassed that I
>hadn't thought of it earlier.
>
>You see, single pixel gifs are useful in colors other than blank.
>
>You can make up split bar charts like this:
>
><img
>src="colorA.gif" height="5" width="129"><img
>src="colorB.gif" height="5" width="58"><img
>src="colorC.gif" height="5" width="91"><img
>src="colorD.gif" height="5" width="122">
>
>or you can do vertical bars
>
><table><tr>
><td valign=bottom align=center><img src=colorA.gif width=50 height=129>
><td valign=bottom align=center><img src=colorA.gif width=50 height=58>
><td valign=bottom align=center><img src=colorA.gif width=50 height=91>
><td valign=bottom align=center><img src=colorA.gif width=50 height=122>
></table>


I'm not exactly sure what the goal of the original problem is, since Minh 
just asked to "display the information", but I think Matt's idea got pretty 
close. You could keep a list of correct answers in a table and grade the 
user's answers against that, returning a percent or number correct. You 
could also return a side-by-side list of the right answers next to the 
user's answers, then calculate a grade at the bottom or wherever.

I put together the poll code below for a project to display some simple 
results in a bar graph format, which is an extension of what deke has 
suggested. Each poll answer is listed on a row with the choice 
(yes/no/maybe in my situation), then a proportional bar whose width is 
based on that answer's percentage of the total votecount (calculated based 
on query counts), then the number of votes. Then under the individual 
numbers of votes is the total votes for the whole poll. And they are sorted 
as ORDER BY vote DESC to put the most-selected answer at the top of the 
list. I can't get this onto a live server at the moment or I'd just link to 
a sample. Looks like this:

Yes     ------- 70% 7 votes
No      ---     30% 3 votes
                          10 votes total

I may have been able to do the queries more efficiently, so if anyone can 
enhance them, please let us know. (Rudy?) The vote field in the database 
just contained yes, no, or maybe based on radio button input from the user, 
and simple counts were done of each unique "answer" in the poll. You could 
do this with any number of answers you wanted.

Don't hesitate to ask more about this or contact me offlist. Hope this code 
isn't ridiculously bad...

Chris
----------------

<CFQUERY NAME="pollquery" DATASOURCE="custservdb">
SELECT vote, COUNT (vote) AS votecount
FROM poll
GROUP BY vote
ORDER BY vote DESC
</CFQUERY>

<CFQUERY NAME="votetotal" DATASOURCE="custservdb">
SELECT *
FROM poll
</CFQUERY>

<html>
<head>
         <title>Poll Results</title>
</head>

<body BGCOLOR="FFFFFF">
Online Poll Results
<TABLE BORDER="0">
<CFOUTPUT QUERY="pollquery">
<CFSET percent = ((#pollquery.votecount# / #votetotal.RecordCount#) *100)>

<TR>
         <TD WIDTH="75" ALIGN="left">#vote#</TD>
         <TD WIDTH="175" ALIGN="left" VALIGN="bottom"><IMG SRC = 
"intranet/art/percentbar.gif" WIDTH = "#percent#" HEIGHT = "12" ALIGN = 
"middle">&nbsp;#NumberFormat(percent, "-999.9")#%</TD>
         <TD WIDTH="100">#pollquery.votecount# votes</TD>
</TR>
</CFOUTPUT>

<TR>
         <TD COLSPAN="2">&nbsp;</TD>
         <TD ALIGN="left">
         <CFOUTPUT>#votetotal.RecordCount# total</CFOUTPUT>
         </TD>
</TR>

</TABLE>
</body>
</html>





More information about the thelist mailing list