-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvote.php
60 lines (55 loc) · 1.18 KB
/
vote.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
$vote = $_REQUEST['vote'];
//get content of textfile
$filename = "data/poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$yes = $array[0];
$no = $array[1];
$virgin = $array[2];
if ($vote == 1) {
$yes = $yes + 1;
}
if ($vote == 2) {
$no = $no + 1;
}
if ($vote == 3) {
$virgin = $virgin + 1;
}
//insert votes to txt file
$insertvote = $yes."||".$no."||".$virgin;
$fp = fopen($filename,"w");
fputs($fp,$insertvote);
fclose($fp);
?>
<table>
<tr>
<td>Kyllä</td>
<td>
<img src="data/poll.gif"
width='<?php echo(100*round($yes/($no+$yes+$virgin),2)); ?>'
height='20'>
<?php echo(100*round($yes/($no+$yes+$virgin),2)); ?>%
</td>
</tr>
<tr>
<td>Ei</td>
<td>
<img src="data/poll.gif"
width='<?php echo(100*round($no/($no+$yes+$virgin),2)); ?>'
height='20'>
<?php echo(100*round($no/($no+$yes+$virgin),2)); ?>%
</td>
</tr>
<tr style="display:none;">
<td>Olen<br>neitsyt</td>
<td>
<img src="data/poll.gif"
width='<?php echo(100*round($virgin/($no+$yes+$virgin),2)); ?>'
height='20'>
<?php echo(100*round($virgin/($no+$yes+$virgin),2)); ?>%
</td>
</tr>
</table>
<p style="margin-top: 8px;">Ääniä yhteensä: <?php echo $no+$yes+$virgin ?></p>