Now that we have our poll data stored, we can make a script to read this data and output the results of the poll.
Create a new file, I'm going to call mine results.php. Type or Copy/Paste the following code into results.php:
<?php
|
|
It may look like a lot, but the script above really isn't that hard to understand. I've tried commenting in it, so that should give you a better idea what's going on. I'll go through and explain each bit.
Lines 4 and 5 get our poll data from the file and unserialize it. This allows us to use the information just like a normal array.
Lines 8, 9 and 10 just define some variables that will be used later in the script. Pretty much the same for lines 13 and 14, they count the number of options our poll has and how many votes have been made on it.
Line 17 echos the poll question. Finally, we get to the most important part of the script, lines 20-33. This is a for loop, the loop starts at zero and ends when it has looped the number of option we have in our poll. Each time through the loop the script calculates the percentage of votes each option has received. Then it just does a couple of echos, it echos the option itself and the number of votes and the percentage of votes for that option.
Finally, line 35 echos the total number of votes the poll has recorded.
If you go ahead and run the results.php file, you should come up with somthing like this:
This is a poll question? Yes 0 votes - 0% No 0 votes - 0% Huh? 0 votes - 0% Total votes: 0
Great! Our results are being displayed, now all we have to do is the voting part of the poll. Go on to the next page to see how this is done.
| Discuss Tutorial: Flat File Poll | 93 Comments |

Gotta love the way you've set it out, Ron. 


im happy now
it will be on my portfolio is that ok

I just have a small problem...the poll shows up twice!
How do I get it to show up only once? 
