Poll Results Tally

Discussion in 'PHP' started by Elle0000, Oct 10, 2006.

  1. #1
    I need to display the results of a short poll, and display the percentage of results for each option in each question.
    I don't know how to calculate the total number of results for each option or how to calculate and display the percentage of each vote.
    One of the questions asks for your favorite month. I used M1-M12 to represent the checked value for the months. Below is what I have for the results script so far. I am most concerned with the code
    
    <?php 
    $Jantotal=0 
    While ($Month=M1) } 
    $Jantotal=sum($M1); } 
    $JanPercent=($Jantotal/(sum($M1));} 
    
    echo $JanPercent of people voted for January 
    January received $Jantotal votes 
    } 
    ?> 
    
    
    PHP:
    Is it even close to calculating and displaying results?
    Thanx muchly

    
    </head> 
    <body> 
    <form action="Poll.html" method="get"> 
    <p class="style1">Your Favorites !</p> 
    <strong> 
    <p class="style5"> Thank you participating in this poll. <br> 
    If any items are incomplete, please hit the back button and complete your submission. </p> </strong> 
    <br> 
    <?php 
    if ( $Flower == "" ) { 
    $error=true; 
    echo "Please vote for your favorite flower."; 
    } else { 
    echo "Your favorite flower is the: $Flower."; } 
    ?> 
    <br><br> 
    <?php 
    if ( $Month == "" ) { 
    $error=true;Vote for your favorite month."; 
    } else { 
    echo "Your favorite month is: $Month."; } 
    ?> 
    <br><br> 
    <?php 
    if ( $Sport== "" ) { 
    $error=true; 
    echo "Please vote for your favorite sport."; 
    } else { 
    echo "Your favorite sport is: $Sport."; } 
    ?> 
    Below are the results for each Month option: 
    
    <?php 
    $Jantotal=0 
    While ($Month=M1) } 
    $Jantotal=sum($M1); } 
    $JanPercent=($Jantotal/(sum($M1));} 
    
    echo $JanPercent of people voted for January 
    January received $Jantotal votes 
    } 
    ?> 
    <br> 
    <input type="Submit" value="BACK" name="Submit"> 
    <br> 
    <p class="style5"> <strong>Thanks for your time.</strong> </p> 
    </form> 
    </body> 
    </html> 
    
    PHP:
     
    Elle0000, Oct 10, 2006 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    Jesus christ you need to learn how to use PHP properly. Try learning the basics first because it looks as though you have no idea what you're doing. The code is messy and doesn't make sense, also you've just placed words places without echoing/printing them and you've used unassigned variables. I tried making sense of your code and this is about as best as I could do with what I was working with:

    
    <?php
    
          While($Month == $M1) {
    
          $Jantotal = count($M1);
    
          $JanPercent = ($Jantotal/(count($M1));
    
          echo "$JanPercent of people voted for January";
    
          echo "January received $Jantotal votes";
    
          }
    
    ?> 
    PHP:
    Also, this "percentage" should have *100 But I have no idea where "$m1" has come from or how this gives a percentage.

    Lee.
     
    BRUm, Oct 10, 2006 IP
  3. Elle0000

    Elle0000 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You are correct. I need to learn how to use it properly. But, I cannot learn, if I am not able to see how the code functions correctly.
    What I posted was the best that I can do right now. I am a novice. I need help. I am taking an online course. This assignment is number two. I have not been taught enough of the basics. I do not understand. The course is too complicated for a beginner. It's a foreign language to me. I can't understand basic vocabulary, let alone construct logical sentences.
    I need help constructing the code. I do not understand enough to copy what is out on the web becasue I do not understand well enough to know what is required, and what can be editted.
    If I want to record/display the data from a question (in a database) asking for a favorite flower, what would the PHP code look like? Say the choices are Daisy, Rose, Lilac and other. How is it done? What are the steps involved?

    P.S. M1 is the variable assigned to the choice of "January". M2 is February and so on through the months. I guess that it's not used correctly.
     
    Elle0000, Oct 10, 2006 IP
  4. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #4
    OK then I advise you to use google and php.net instead, it's far more beneficial than a course you do not understand. Also, buy a book, a good one that I have is: "Visual & Quick Pro Guide - PHP and MySQL" written by Larry Ullman.

    If you google "PHP basics" there are brilliant websites out there that really break it down and you will be able to understand. :)

    Good luck,

    Lee.
     
    BRUm, Oct 11, 2006 IP