|
|
|
|
|
There will be more tutorials, if I have time.
|
|
How I made the poll
|
|
Intro
This poll does not need a database. The interim results are simply written into
and stored in a textfile.
You should already have some experience with HTML, PHP and SVG (and possibly JavaScript), because this text is basically about the special feature of reading and showing the poll-results in an SVG-file with dynamically changing bars.
The file containing the actual poll:
This is the form for the poll...
...and here is the PHP-code for the analysis of the submitted data:
The poll-results are now written into the text-file and at the same time a new window pops up:
"Thank you very much for your answer... - ... please click here to see the results"
The file showing the results:
With the following code the results are read from the text-file, converted into percent and inserted into the HTML-file:
And furthermore:
The SVG-part:
Now to the interesting part, the presentation of the results using SVG.
I have embedded the SVG-file into the HTML-file for the results using:
As you can see, the suffix is not .svg but .psvg. In order to make .psvg-files readable, you will have to add a respective entry in the .htaccess-file on your server. How this is to be done, you can learn here on the interesting site of carto.net, where I also learned nearly everything for the following part.
Many thanks to the authors!
The .psvg-file begins with this code for the header:
Then follows the code for the filters for the bars, simply normal SVG-Code.
Then, here is the code, which reads the results from the text-file and converts the resulting number into percentage of the full length:
Finally, I replaced the usually fixed number for the width of each bar by the PHP-code that inserts the beforehand defined variable for the dynamic percental width of the bar:
Note: In this particular file of mine the minimum length of each bar is 7 pixel, so that the very tip of the bar is also visible when there is no answer.
That was it.
|
|