WordPress.org

Ready to get started?Download WordPress

Forums

WP-Polls
Math calculation error - PHP warning! (6 posts)

  1. biswajeet
    Member
    Posted 2 years ago #

    PHP Warning:  Division by zero in /***/plugins/wp-polls/wp-polls.php on line 605

    I think this error result from when having some total no. of votes but a particular choice answer have 0 vote and while calculating % for it. It shows as 1% rather than 0%

    need rectification,
    thanks.

    http://wordpress.org/extend/plugins/wp-polls/

  2. biswajeet
    Member
    Posted 2 years ago #

    Ok I think I have found the error:
    The error was in the following code -

    // Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
    if($poll_multiple_ans == 0) {
     $poll_answer_percentage_array[] = $poll_answer_percentage;
     if(sizeof($poll_answer_percentage_array) == sizeof($poll_answers)) {
       $percentage_error_buffer = 100 - array_sum($poll_answer_percentage_array);
       $poll_answer_percentage = $poll_answer_percentage + $percentage_error_buffer;
       if($poll_answer_percentage < 0) {
        $poll_answer_percentage = 0;
       }
     }
    }

    Actually if you allow user to select more than one answer, then only above code should execute and for that to check ($poll_multiple_ans == 1). On changing this now works fine but still gives error for multiple vote selection case and the error is showing 1% for 0 votes.

  3. figaro1818
    Member
    Posted 2 years ago #

    Thanks for directing me over to this thread. I tried ($poll_multiple_ans == 1) and the only change I see is that instead of the 8 Votes for No being 0% it is now 27%. But the Yes votes are still coming out to 103%. Any ideas??? Thank you again for any help.

    http://iszeekrewardsascam.com/

  4. Marko Heijnen
    Member
    Posted 1 year ago #

    The line on that error is wrong. I'm now trying to fix some of the issues on github.

    I change the line:
    $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvoters)*100));
    to
    $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvotes)*100));

  5. biswajeet
    Member
    Posted 1 year ago #

    Thanks @Marko Heijnen

  6. kredit-otziv
    Member
    Posted 1 year ago #

    thank you Marko Heijnen this really helped.
    but I think the error is not reported the total number of voters

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.