Skip to main content
February 15, 2011
Question

Trying to make a simple voting/poll system.

  • February 15, 2011
  • 2 replies
  • 2013 views

Hi everyone. I am trying to make a very basic voting system and the only part i am having trouble with is the results. The DB table has QuestionID and VoteResult. In the VoteResults you can enter the word "Excellent", "Good", "Bad". I would like it to show the result of all the "excellent" vote and add a recordcount next to it showing how many people voted Excellent and how many selected good...and so on.I also tried showing the results with cfchart, but i have a very limited knowledge or the cfchart and just couldn't get it to work....so ya.

For example:

Excellent 20 votes

Good 5 votes

Bad 75 votes

Hope this makes sense.

Thanks

    This topic has been closed for replies.

    2 replies

    Owainnorth
    Inspiring
    February 15, 2011

    You need to use Grouping in your SQL query. Not knowing the structure, this is the kind of thing you're after:

    SELECT

      VoteResult,

      count(*)

    FROM

      VoteResults

    WHERE

      QuestionID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#QuestionID#" />

    GROUP BY

      VoteResult

    That should give you the number of each reply for your question.

    You should then be able to feed that very simply into a CfChart.

    Hope that helps!

    O.

    February 15, 2011

    Here is my code

    =====   Code  =====

    <cfparam name="URL.Question" default="1" />

    <cfquery name="qResults" datasource="poll">
    SELECT QuestionID,COUNT(VoteResults) AS Votes
    FROM PollSystem
    WHERE QuestionID = <cfqueryparam value="#URL.Question#" cfsqltype="cf_sql_numeric">
    GROUP BY QuestionID
    </cfquery>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

      <cfchart format="flash"
                 scalefrom="0"
               scaleto="100"> 

    <cfchartseries type="bar" 
                   query="qResults">

    <cfchartdata item="Excellent" value="#qResults.Votes#">
    <cfchartdata item="Good" value="#qResults.Votes#">
    <cfchartdata item="Bad" value="#qResults.Votes#">

    </cfchartseries>
    </cfchart>

    </body>
    </html>

    ===== End code =========

    It's showing me 4 bars, 3 are named according to the code, but there's an extra one with no name and i don't know where it came from. Plus it's show the entire vote results, for example questionid 1 has 9 votes in total. it's counting the excellent, good and bad votes together.

    Again the database table only consists of QuestionID and VoteResults. that's it.

    Owainnorth
    Inspiring
    February 15, 2011

    Have you dumped out the Query result first to check the data is correct? Sack the graph off for now as obviously there's an issue with the query.

    Inspiring
    February 15, 2011

    Hi,

    If you go through the help documentation of CFCHARt, you would be understanding, its quite easy and its self explanatory also.

    Please go through this link.

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7930.html

    For your query, use this one

    <cfchart style="blue"
             format="png"
             scalefrom="0"
             scaleto="100"
             pieslicestyle="solid"
           
             chartWidth="550" chartHeight="510" >
        <cfchartseries
                     type="pie"
                     serieslabel="Voting system"
                     seriescolor="blue" >
                     <cfchartdata item="Excellent" value="20">
            <cfchartdata item="Good " value="5" >
            <cfchartdata item="Bad" value="75">

        </cfchartseries>
    </cfchart