poll getal + procent
(in de database staan ze in getallen dus niet in procenten)
Code (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?
# Filename : poll.php
class poll
{
# Show options function
function showOptions()
{
# Get newest poll
$data = $this->getPoll();
# Split options
$options = explode(",", $data['poll_keuzes']);
# Count options for loop
$aant = count($options)-1;
$poll .= "<b>" . $data['poll_stelling'] . "</b><br />";
$poll .= "<form method=\"POST\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
# Loop and make input radios
for($i = 0; $i <= $aant; $i++)
{
$j = $i+1;
$poll .= "<input type=\"radio\" value=\"" . $j . "\" name=\"poll\" />" . $options[$i] . "<br />";
}
# End form
$poll .= "<input type=\"submit\" name=\"vote\" value=\"Stem\" class=\"button\" />";
$poll .= "</form>";
# Show pollid no. and poll date
// $poll .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
//$poll .= "<p><a href=\"template/poll/archives.php\">Bekijk archief!</a>";
return $poll;
}
function updateVotes($vote)
{
# Get newest poll
$data = $this->getPoll();
# Split the vote scores
$stemmen = explode(",", $data['poll_scores']);
# add one to the selected option
$vote--;
(int) $stemmen[$vote]++;
# Remake the data
$stem = implode(",", $stemmen);
# Add to database
$sql1 = "UPDATE `poll` SET `poll_scores` = '" . $stem . "' WHERE `poll_id` = '" . $data['poll_id'] . "'";
$ip = $_SERVER['REMOTE_ADDR'];
$sql2 = "INSERT INTO `votes` SET `vote_ip` = '" . $ip . "', `vote_datum` = '" . time() . "'";
# Run db class
$db = new database;
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
}
function getPoll()
{
# Select the newest poll
$sql = "SELECT * FROM `poll` ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
function showResults()
{
# Get data
$data = $this->getPoll();
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b>";
$results .= "<h5>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"template/images/indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</h5>";
$results .= "<h5>". "Totaal aantal stemmen: " . $votes . "</h5>";
# Show pollid no. and poll date
// $results .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
//$results .= "<p><a href=\"template/poll/archives.php\">Bekijk archief!</a>";
return $results;
}
function archResults($id)
{
# Get data
$data = $this->archPoll($id);
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b>";
$results .= "<p>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"template/images/indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</p>";
$results .= "<h5>". "Totaal aantal stemmen: " . $votes . "</h5>";
# Show pollid no. and poll date and poll name
//$results .= "<p>PolhhlID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
//$results .= "<p><a href=\"archives.php\">Terug!</a>";
return $results;
}
function archPoll($id)
{
# Select the newest poll
$sql = "SELECT * FROM `poll` WHERE `poll_id` = '" . $id . "' ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
# Calculate indicator size
function imgPXL($tot, $opt)
{
$pro = $tot / 100;
$num = $opt / $pro;
return (int) $num;
}
}
?>
# Filename : poll.php
class poll
{
# Show options function
function showOptions()
{
# Get newest poll
$data = $this->getPoll();
# Split options
$options = explode(",", $data['poll_keuzes']);
# Count options for loop
$aant = count($options)-1;
$poll .= "<b>" . $data['poll_stelling'] . "</b><br />";
$poll .= "<form method=\"POST\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
# Loop and make input radios
for($i = 0; $i <= $aant; $i++)
{
$j = $i+1;
$poll .= "<input type=\"radio\" value=\"" . $j . "\" name=\"poll\" />" . $options[$i] . "<br />";
}
# End form
$poll .= "<input type=\"submit\" name=\"vote\" value=\"Stem\" class=\"button\" />";
$poll .= "</form>";
# Show pollid no. and poll date
// $poll .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
//$poll .= "<p><a href=\"template/poll/archives.php\">Bekijk archief!</a>";
return $poll;
}
function updateVotes($vote)
{
# Get newest poll
$data = $this->getPoll();
# Split the vote scores
$stemmen = explode(",", $data['poll_scores']);
# add one to the selected option
$vote--;
(int) $stemmen[$vote]++;
# Remake the data
$stem = implode(",", $stemmen);
# Add to database
$sql1 = "UPDATE `poll` SET `poll_scores` = '" . $stem . "' WHERE `poll_id` = '" . $data['poll_id'] . "'";
$ip = $_SERVER['REMOTE_ADDR'];
$sql2 = "INSERT INTO `votes` SET `vote_ip` = '" . $ip . "', `vote_datum` = '" . time() . "'";
# Run db class
$db = new database;
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
}
function getPoll()
{
# Select the newest poll
$sql = "SELECT * FROM `poll` ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
function showResults()
{
# Get data
$data = $this->getPoll();
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b>";
$results .= "<h5>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"template/images/indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</h5>";
$results .= "<h5>". "Totaal aantal stemmen: " . $votes . "</h5>";
# Show pollid no. and poll date
// $results .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
//$results .= "<p><a href=\"template/poll/archives.php\">Bekijk archief!</a>";
return $results;
}
function archResults($id)
{
# Get data
$data = $this->archPoll($id);
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b>";
$results .= "<p>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"template/images/indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</p>";
$results .= "<h5>". "Totaal aantal stemmen: " . $votes . "</h5>";
# Show pollid no. and poll date and poll name
//$results .= "<p>PolhhlID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
//$results .= "<p><a href=\"archives.php\">Terug!</a>";
return $results;
}
function archPoll($id)
{
# Select the newest poll
$sql = "SELECT * FROM `poll` WHERE `poll_id` = '" . $id . "' ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
# Calculate indicator size
function imgPXL($tot, $opt)
{
$pro = $tot / 100;
$num = $opt / $pro;
return (int) $num;
}
}
?>
dit is de poll.php ik weet niet waar ik moet veradneren en bij sommige stukje script heb ik een commentaar van gemaakt omdat ik die misschien later wil gebruiken maar nu niet.
alvast bedankt.
Kortom, je kunt die variabele gewoon gebruiken om het aantal stemmen te echoën...
$results .= $scores[$i] .
eronder zetten?
$results .= $votes;
eronder zetten. $votes bevat immers het aantal stemmen.
ps. @Gamer: het totaal aantal votes ja. Maar als ik het goed begrijp gaat het om het aantal votes per item.
Gewijzigd op 01/01/1970 01:00:00 door Joren de Wit
dus het is wel : $results .= $scores[$i] . ;)
maar bedankt allemaal
Gewijzigd op 01/01/1970 01:00:00 door M Rodrigo
Mooi dat 't nu werkt.
$results .= $scores[$i] . "<br />"; (met "<br />") om het te laten werken
want als ik alleen $results .= $scores[$i] . ; werkt het niet ?
EDIT:
Ik het wel opgelost met $results .= $scores[$i] . "";
toch vind ik het nog raar dat ie het anders niet werkt
Gewijzigd op 01/01/1970 01:00:00 door M Rodrigo
Dit zal dus gewoon werken.
De oplossing die jij gevonden hebt werkt wel, maar is niet netjes. Waarom zou je er een lege string aan vast plakken? Dat is vrij nutteloos...
Maar kan ik nu ook een div eraan plakken (om die text een style te geven)
en hoe moet dat dan in zo en script
alles werkt nu toppie