Can anyone please tell me how i can echo the results of my poll?
<?php setcookie("poll","1",time()+86400*30); if($_COOKIE['poll'] == 1) { die ("you've already voted in this poll"); } ELSE { echo "'Thank you for your vote"; } $vote = $_REQUEST['vote']; //get content of textfile $filename = "poll_result.txt"; $content = file($filename); //put content in array $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) { $yes += 1; } if ($vote == 1) { $no += 1; } //insert votes to txt file $insertvote = $yes."||".$no; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp); ?>Results:
contractor: | <?php echo(100*round($yes/($no+$yes),2)); ?>% |
myself: | <?php echo(100*round($no/($no+$yes),2)); ?>% | Number of votes: | <?php echo ($yes+$no); ?> |