> Jeg har nu stemt på alle mulighederne - får ingen
> fejlmeldinger, men den vender blot tilbage til forsiden -
> uden at vise nogen resultater.
Ja, det er mit problem. Jeg ved ikke hvordan jeg får den til at vise
resulatet ?
> Den fejlmelding kæmpede jeg også med i går - der er en
> syntaksfejl i din pollfunctions.php. Kan du ikke lægge den
> op på
http://pastebin.priber.dk, så vi andre også kan se
> den..? Post URL, som du får, her i gruppen.
Ja, har rettet den. Her er den færdige pollfunctions.php :
<?php
$dbtable_polls = "polls";
$dbtable_pollvotes = "pollvotes";
$cookieprefix = "mypoll";
$redirectto = "
http://skrivdinhjemmesideher.dk";
if($_POST[do_vote] and $_POST[pid] and $_POST[vid]) {
CastVote($_POST[pid], $_POST[vid]);
}
function HaveVoted($pid) {
global $cookieprefix;
if(($_COOKIE[$cookieprefix."vote".$pid]) AND
($_COOKIE[$cookieprefix."poll".$pid] == $pid)) {
return true;
} else {
return false;
}
}
function CastVote($pid, $vote) {
global $dbtable_pollvotes; global $cookieprefix; global $redirectto;
if(HaveVoted($pid) != true) {
$addvote = mysql_query("insert into $dbtable_pollvotes (pollid, vote)
values ('$pid','$vote')");
setcookie($cookieprefix."vote".$pid, $vote, time()+999999999);
setcookie($cookieprefix."poll".$pid, $pid, time()+999999999);
header("location: $redirectto");
}
}
function ShowPoll($pid) {
global $dbtable_polls;
$query = mysql_query("select * from $dbtable_polls where id='$pid'");
if(mysql_num_rows($query) > 0)
{
$q = stripslashes(mysql_result($query, 0, "question"));
$num = mysql_result($query, 0, "numofanswers");
$kode .= "<div class=\"pollquestion\">$q</div>";
$kode .= "<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">";
$i = 1;
while($i != $num+1) {
$a = stripslashes(mysql_result($query, 0, "answer".$i));
$kode .= "<div class=\"pollanswer\"><input type=\"radio\" name=\"vid\"
value=\"$i\" />$a</div>";
$i++;
}
$kode .= "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />";
$kode .= "<br /><input type=\"submit\" name=\"do_vote\" value=" - Stem - "
class=\"button\" />";
$kode .= "</form>";
}
return $kode;
}
function ShowResults($pid) {
global $dbtable_polls; global $dbtable_pollvotes;
$query = mysql_query("select * from $dbtable_polls where id='$pid'");
$q = stripslashes(mysql_result($query, 0, "question"));
$num = mysql_result($query, 0, "numofanswers");
$kode .= "<div class=\"pollquestion\">$q</div>";
$votesquery = mysql_query("select count(id) from $dbtable_pollvotes where
pollid='$pid'");
$totalvotes = mysql_result($votesquery, 0, 0);
$i = 1;
$kode .= "<table style=\"width: 95%;\" class=\"text\">";
while($i != $num+1) {
$a = stripslashes(mysql_result($query, 0, "answer".$i));
$resultquery = mysql_query("select count(id) from $dbtable_pollvotes
where pollid='$pid' and vote='$i'");
$votes = mysql_result($resultquery, 0, 0);
if($votes > 0) {
$average = round(100 * $votes / $totalvotes, 2);
} else {
$average = "0";
}
$kode .= "<tr>";
$kode .= "<td colspan=\"2\"><div class=\"pollanswer\">$a:</div></td>";
$kode .= "</tr><tr>";
$kode .= "<td style=\"width: 75%;\"><span class=\"pollbar\"
style=\"width: $average%;\"></td>";
$kode .= "<td></span> <span style=\"text-align: right; font-weight:
bold;\">$average%</span></td>";
$kode .= "</tr>";
$i++;
}
$kode .= "</table>";
$kode .= "<br /><div style=\"text-align: center;\">Stemmer i alt:<br
/><b>$totalvotes</b></div>";
return $kode;
}
?>
--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! =>
http://www.html.dk/tutorials