The page on the server called by the JavaScript is a PHP file calledWhich language do you like the most?
PollVote.php
as below.
The value is sent from the JavaScript, and the following happens:
PollResult.txt
file where we store the data from the poll.
It is stored like this:
4||3||11||17||7||1||1
PollResult.txt
file.
<?php $vote = $_REQUEST['vote']; // Get content of textfile. $filename = "PollResult.txt"; $content = file( $filename ); // Put content in array. $array = explode( "||", $content[0] ); $C = $array[0]; $Java = $array[1]; $Lisp = $array[2]; $Perl = $array[3]; $PHP = $array[4]; $Prolog = $array[5]; $Python = $array[6]; switch ( $vote ) { case 0: $C += 1; break; case 1: $Java += 1; break; case 2: $Lisp += 1; break; case 3: $Perl += 1; break; case 4: $PHP += 1; break; case 5: $Prolog += 1; break; case 6: $Python += 1; break; } // Insert votes to txt file. $insertVote = $C . "||" . $Java . "||" . $Lisp . "||" . $Perl . "||"; $insertVote .= $PHP . "||" . $Prolog . "||" . $Python; $fp = fopen( $filename, "w" ); fputs ( $fp, $insertVote ); fclose( $fp ); ?> <?php $total = $C + $Java + $Lisp + $Perl + $PHP + $Prolog + $Python; ?> <table> <tr> <td rowspan="7"> Results: (Total votes = <?php echo( $total ); ?>) </td> <td>C/C++:</td> <td> <img src='poll.gif' height='20' width = '<?php echo( 100*round($C/$total, 2) ); ?>' /> <?php echo( 100*round($C/$total, 2) ); ?>% </td> </tr> <tr> <td>Java:</td> <td> <img src='poll.gif' height='20' width = '<?php echo( 100*round($Java/$total, 2) ); ?>' /> <?php echo( 100*round($Java/$total, 2) ); ?>% </td> </tr> <tr> <td>Lisp:</td> <td> <img src='poll.gif' height='20' width = '<?php echo( 100*round($Lisp/$total, 2) ); ?>' /> <?php echo( 100*round($Lisp/$total, 2) ); ?>% </td> </tr> <tr> <td>Perl:</td> <td> <img src='poll.gif' height='20' width = '<?php echo( 100*round($Perl/$total, 2) ); ?>' /> <?php echo( 100*round($Perl/$total, 2) ); ?>% </td> </tr> <tr> <td>PHP:</td> <td> <img src='poll.gif' height='20' width = '<?php echo( 100*round($PHP/$total, 2) ); ?>' /> <?php echo( 100*round($PHP/$total, 2) ); ?>% </td> </tr> <tr> <td>Prolog:</td> <td> <img src='poll.gif' height='20' width = '<?php echo( 100*round($Prolog/$total, 2) ); ?>' /> <?php echo( 100*round($Prolog/$total, 2) ); ?>% </td> </tr> <tr> <td>Python:</td> <td> <img src='poll.gif' height='20' width = '<?php echo( 100*round($Python/$total, 2) ); ?>' /> <?php echo( 100*round($Python/$total, 2) ); ?>% </td> </tr> </table> |
My father was a night watchman, but he was a victim of technology. He was replaced by a lock. — Colin Quinn |