Gå til innhold

Gjøre om på en vote


Anbefalte innlegg

Hallo

 

Jeg har en vote her som hvor resultatet viser Alternativene, Prosent og Antall Stemmer.

Det jeg vil er at anntal stemmer skal bare usynlig, og de skal plusses sammen og summen skal stå under resultatet 'xx mange har stemt' Skjønner?

 

<?php
// En: Begin PHP Code / Fr: Debut code PHP
/******************************************************************************\
* PHP Poll                                     Version 1.0                     *
* Copyright 2000 Frederic TYNDIUK (FTLS)       All Rights Reserved.            *
* E-Mail: [email protected]                     Script License: GPL             *
* Created  02/28/2000                          Last Modified 02/28/2000        *
* Scripts Archive at:                          http://www.ftls.org/php/        *
*******************************************************************************/
// Necessary Variables:

$RESULT_FILE_NAME = "pool/poll_data.txt";
// En: Absolute path and name to file contain poll data.
// Fr: Chemin absolu (complet) et Nom du fichier contenant les donne.

$QUESTION = "Siden er";
// En: Question Text.
// Fr: Texte de la question.
$ANSWER = array("Best", "Bra", "OK", "Dårlig", "Dårligst");
// En: All answer.
// Fr: Reponses possibles

$IMG_DIR_URL = "./vote";
// En: URL Directory of poll graphs.
// Fr: URL du repertoire des images.

$REVOTE_TIME = 3600;
// En: Time (second) after people can revote, use cookies.
// Fr: Temps en second apres lequel une personne peut revoter.

// End  Necessary Variables section
/******************************************************************************/

if (! $vote && ! $result) {
echo "<FORM METHOD=\"POST\">\n";
echo "<TABLE WIDTH=100% BORDER=0><TR><TD><TABLE WIDTH=\"100%\" BORDER=0>\n";
echo "<TR><TH align=\"left\">$QUESTION</TH></TR>\n";
while (list($key, $val) = each($ANSWER)) {
 echo "<TR><TD align=\"left\"><INPUT TYPE=\"radio\" NAME=\"answer\" VALUE=\"$key\"> $val</TD></TR>\n";
} 
echo "<TR><TD align=\"center\"><INPUT TYPE=\"Submit\" NAME=\"vote\" VALUE=\" Vote \"></TD></TR>\n";
echo "<TR><TD align=\"center\"><INPUT TYPE=\"Submit\" NAME=\"result\" VALUE=\" See Result \"></TD></TR>\n";
echo "</TABLE></TD></TR></TABLE></FORM>";
} else {

$file_array = file($RESULT_FILE_NAME); // or error("Can not open \$RESULT_FILE_NAME");

// En: Save result
// Fr: Enregistre le resultat
if ($answer < count($ANSWER) && $vote) {
 if (count($file_array) < count($ANSWER))  {
 	$file_array = array("0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n");
 }
 $old_answer = $file_array[$answer];
 $old_answer = preg_replace("/\n\r*/", "", $old_answer);
 $file_array[$answer] = ($old_answer + 1)."\n";

 $file = join('', $file_array);
 $fp = fopen("$RESULT_FILE_NAME", "w"); //or error("Can not write \$RESULT_FILE_NAME");
 flock($fp, 1);
 fputs($fp, $file);                                                     
 flock($fp, 3);
 fclose($fp);
}

// En: Display result
// Fr: Affiche le resultat
while (list($key, $val) = each($file_array)) {
 $total += $val;
}

echo "<TABLE CELLSPACING=2 CELLPADDING=1 BORDER=0>";

while (list($key, $val) = each($ANSWER)) {
 $percent =  $file_array[$key] * 100 / $total;
 $percent_int = floor($percent);
 $percent_float = number_format($percent, 1);
 $tp += $percent_float;
 echo "<tr><td> $ANSWER[$key] </td><td>$percent_float % </td><td>$file_array[$key]</td></tr>";
}

echo "</TABLE><br>";
}

?>

Lenke til kommentar
Videoannonse
Annonse
Gjest Slettet-rXRozPkg

Bytt ut denne delen:

echo "<TABLE CELLSPACING=2 CELLPADDING=1 BORDER=0>";

while (list($key, $val) = each($ANSWER)) {
 $percent =  $file_array[$key] * 100 / $total;
 $percent_int = floor($percent);
 $percent_float = number_format($percent, 1);
 $tp += $percent_float;
 echo "<tr><td> $ANSWER[$key] </td><td>$percent_float %</td><td>$file_array[$key]</td></tr>";
}
echo "</TABLE><br>";

 

Med denne:

echo "<TABLE CELLSPACING=2 CELLPADDING=1 BORDER=0>";

$totalt_ant_stemmer = 0;
while (list($key, $val) = each($ANSWER)) {
 $totalt_ant_stemmer += $file_array[$key];
 $percent =  $file_array[$key] * 100 / $total;
 $percent_int = floor($percent);
 $percent_float = number_format($percent, 1);
 $tp += $percent_float;
 echo "<tr><td> $ANSWER[$key] </td><td>$percent_float % </td></tr>";
}
echo "<tr><td colspan='2'>Antall stemmer: $totalt_ant_stemmer</td></tr>"
echo "</TABLE><br>";

Endret av Slettet-rXRozPkg
Lenke til kommentar
Gjest Slettet-rXRozPkg

Ehm, så det ikke før nå, bare bruk $total ;)

 

echo "<TABLE CELLSPACING=2 CELLPADDING=1 BORDER=0>";

while (list($key, $val) = each($ANSWER)) {
$percent =  $file_array[$key] * 100 / $total;
$percent_int = floor($percent);
$percent_float = number_format($percent, 1);
$tp += $percent_float;
echo "<tr><td> $ANSWER[$key] </td><td>$percent_float % </td></tr>";
}
echo "<tr><td colspan='2'>Antall stemmer: $total</td></tr>"
echo "</TABLE><br>";

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...