Jump to content

voting help


rchandran0023

Recommended Posts

i have dloaded a nice little simple voting app but cant get it to work.

It will not display the stats when the "view results" button is clicked.

Iv tried to put "$results = $_POST['results'];" in different places in the code but the best i can get is it will pop up with the stats but they wont be correct. ???

Any help would be much appreciated and im sure it will help others as well. I am an official phpfreaks donating member.

.........................................................................

<code>

<?

    // $results = $_POST['results'];

    $filename = "poll.txt";

    $fl=fopen($filename,'r');

 

    $name = fgets($fl, 4096);

    $options[0] = fgets($fl, 5);

 

    $temp = $options[0];

    while ($temp) {

        $theoptions[$temp] = fgets($fl, 4096);

        $temp = $temp - 1;

    }

 

    $temp = $options[0];

    while ($temp) {

        $thevalues[$temp] = fgets($fl, 4096);

        $temp = $temp - 1;

    }

    fclose($fl);

 

 

 

 

    if ($results) {

 

        echo "$name<br>";

        $temp = $options[0];

        while ($temp) {

            if ($thevalues[$temp] == 0) {

                $percent = 0;

            } else {

 

                $tempnum = $options[0];

                $total = 0;

                while ($tempnum) {

                    $total += Trim($thevalues[$tempnum]);

                    $tempnum = $tempnum - 1;

                }

 

                $percent = 100 * Trim($thevalues[$temp]) / $total;

                if (strlen($percent) > 4) {

                  $percent = substr($percent, 0, 4);

                }

            }

 

            echo "$theoptions[$temp]: $percent% ($thevalues[$temp] votes)<br><br>";

            $temp = $temp - 1;

        }

 

  } elseif ($vote) {

 

      echo "You voted for $theoptions[$optradio]<br>";

 

      unlink($filename);

      $fl = fopen($filename, 'w');

      fputs($fl, "$name");

      fputs($fl, "$options[0]");

 

      $temp = $options[0];

      while ($temp) {

          fputs($fl, "$theoptions[$temp]");

          $temp = $temp - 1;

      }

 

      $temp = $options[0];

      while ($temp) {

          if ($temp == $optradio) {

              fputs($fl, "$thevalues[$temp]" + 1);

              fputs($fl, "\n");

              $temp = $temp - 1;

          } else {

              fputs($fl, "$thevalues[$temp]");

              $temp = $temp - 1;

          }

      }

      fclose($fl);

 

  } else {

      echo "$name<br>";

      $temp = $options[0];

      echo "<form method=\"post\" action=\"$PHP_SELF\">";

 

      while ($temp) {

          echo "<input type=\"radio\" name=\"optradio\" value=\"$temp\"> $theoptions[$temp]<br>";

          $temp = $temp - 1;

   

      }

      echo "<input type=\"submit\" name=\"vote\" value=\"Vote\">";

      echo "<input type=\"submit\" name=\"results\" value=\"View Results\">";

   

 

  }

 

?>

</code>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.