ich mach mal den anfang: ein skript für eine Umfrage:
PHP-Code:
<?
if (isset($Abschicken))
{
setcookie("cfg_umfrage", "gestimmt",time()+3600);
}
$dateiname="umfrage.txt";//DATEI IN DER DIE ERGEBNISSE GESPEICHERT WERDEN darin steht zum beispiel: 1;2;0;0;0;
$anzahl=5;//ANZAHL ANTWORTEN
$frage="Die Frage"; //DIE FRAGE
$color[0]="#000066";//Farbe der balken
$color[1]="#418BC2";
$color[2]="#000066";
$color[3]="#418BC2";
$color[4]="#000066";
$text[0]="Antwort 1";
$text[1]="Antwort 2";
$text[2]="Antwort 3";
$text[3]="Antwort 4";
$text[4]="Antwort 5";
echo "<html>
<head>
<title>".$frage."</title>
</head>
<link rel=\"stylesheet\" href=\"/styles/standard.css\">
<style type=\"text/css\">
<!--
.button{border-width:0; background-color: #3399CC; border-color: #3399CC; font-size: 8pt; font-family: \"Arial,Helvetica\"; color: #000066}
-->
</style>
<body bgcolor=\"#ffffff\">";
if (isset($Abschicken) or $ergebnis=='show')
{
$file=fopen($dateiname,"r");
$zeile=fgets($file,4096);
$ausgelesen=split(";",$zeile);
for ($i=0;$i<=$anzahl-1;$i++)
{
//echo $ausgelesen[$i]."<br>";
}
fclose($file);
if (isset($wert)and !isset($cfg_umfrage))
{
$file=fopen($dateiname,"w");
$ausgelesen[$wert]=$ausgelesen[$wert]+1;
for ($i=0;$i<=$anzahl-1;$i++)
{
$schreiben.=$ausgelesen[$i].";";
}
$erfolg=fwrite($file,$schreiben);
fclose($file);
}
$file=fopen($dateiname,"r");
$zeile=fgets($file,4096);
$ausgelesen=split(";",$zeile);
echo "<table border=\"0\">\n
<tr><td colspan=\"3\"><b>".$frage."</b></td></tr>";
for ($i=0;$i<=$anzahl-1;$i++)
{
$gesamt=$ausgelesen[$i]+$gesamt;
//echo $ausgelesen[$i]."<br>";
}
fclose($file);
for ($z=0;$z<=$anzahl-1;$z++)
{
$prozentual[$z]=$ausgelesen[$z]/$gesamt*100;
echo "<tr><td>".$text[$z]."</td>\n";
echo "<td width=\"100\"><table cellpading=\"0\" cellspacing=\"0\" border=\"0\" >\n
<tr>\n<td bgcolor=\"".$color[$z]."\" height=\"15\" width=\"";
printf ("%.0f",$prozentual[$z]);
echo "\"></td>\n</tr>\n</table>\n</td>\n";
echo "<td>";
printf ("%.1f",$prozentual[$z]);
echo "%</td>\n</tr>\n";
}
echo"<tr><td colspan=\"3\">Stimmen insgesamt: ".$gesamt."</td></tr>";
echo "</table>\n<br>
Haben Sie Anregungen, Wünsche oder Fragen, dann nehmen Sie <a href=\"/schnell_info/kontakt/kontakt.php3\" target=\"hauptframe\">Kontakt</a> zum Webmaster auf.";
}
else
{
echo "<form method=\"post\" action=\"$PHP_SELF\">
<table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td colspan=\"2\"><b>".$frage."</b></td>
</tr>";
for ($a=0;$a<=$anzahl-1;$a++)
{
echo "
<tr>
<td>
<input type=\"radio\" name=\"wert\" value=\"".$a."\">
</td>
<td>".$text[$a]."</td>
</tr>";
}
echo "<tr>
<td colspan=\"2\">
<input type=\"submit\" name=\"Abschicken\" class=\"button\" value=\"Stimme abgeben\">
</td>
</tr>
<tr>
<td colspan=\"2\">
<a href=\"umfrage.php3?ergebnis=show\">Ergebnisse anzeigen</a>
</td>
</tr>
</table>
</form>";
}
?>
wer fragen hat kann posten!