Page 1 of 1
Hand Writing Poll Results Scripts
Posted: Tue Oct 10, 2006 12:39 pm
by Elle0000
I need to display the results of a short poll, and display the percentage of results for each option in each question.
I don't know how to calculate the total number of results for each option or how to calculate and display the percentage of each vote.
One of the questions asks for your favorite month. I used M1-M12 to represent the checked value for the months. Below is what I have for the results script so far.
Thanx muchly
Code: Select all
</head>
<body>
<form action="Poll.html" method="get">
<p class="style1">Your Favorites !</p>
<strong>
<p class="style5"> Thank you participating in this poll. <br>
If any items are incomplete, please hit the back button and complete your submission. </p> </strong>
<br>
<?php
if ( $Flower == "" ) {
$error=true;
echo "Please vote for your favorite flower.";
} else {
echo "Your favorite flower is the: $Flower."; }
?>
<br><br>
<?php
if ( $Month == "" ) {
$error=true;Vote for your favorite month.";
} else {
echo "Your favorite month is: $Month."; }
?>
<br><br>
<?php
if ( $Sport== "" ) {
$error=true;
echo "Please vote for your favorite sport.";
} else {
echo "Your favorite sport is: $Sport."; }
?>
Below are the results for each Month option:
<?php
$Jantotal=0
While ($Month=M1) }
$Jantotal=sum($M1); }
$JanPercent=($Jantotal/(sum($M1));}
echo $JanPercent of people voted for January
January received $Jantotal votes
}
?>
<br>
<input type="Submit" value="BACK" name="Submit">
<br>
<p class="style5"> <strong>Thanks for your time.</strong> </p>
</form>
</body>
</html>
Posted: Tue Oct 10, 2006 12:59 pm
by feyd
Where and how is the data from previous submissions being stored so that statistical calculations can be made?
Posted: Tue Oct 10, 2006 1:08 pm
by Elle0000
The data is being stored in a MYSQL database. The file name will be pollresults.php.
The poll form will post the results to this file.
Posted: Tue Oct 10, 2006 1:13 pm
by feyd
Where's/what's the code that fetches the data form the database?
Posted: Tue Oct 10, 2006 1:20 pm
by Elle0000
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Please forgive my ignorance. I am not sure what info you need.
Below is the code for the poll form itself.
The hosting company that I use has GUI enabled. I only need to post my HTML and PHP files in a certain folder.
[syntax="html"]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>My Favorites</title>
</head>
<body>
<FORM style="MARGIN-TOP: 0px; MARGIN-LEFT: 0px; MARGIN-RIGHT: 0px"
name=Favorites action=pollresults.php method=post
target="">
<table width="75%" border="1" align="center" bordercolor="#333399">
<tr bordercolor="#333399">
<th scope="col">
<TABLE width=123 border=1 cellPadding=2 cellSpacing=0 bordercolor="#333399" bgColor=#ddeeff>
<TBODY>
<TR>
<TD bgColor=#5588cc>
<TABLE width="100%" border=1 cellPadding=0 cellSpacing=0 bordercolor="#FFFFFF">
<TBODY>
<TR>
<TD align=middle>
<div align="center"><FONT face=verdana,arial,sans-serif color=#ffffff size=2><B>My Favorites</B></FONT></div>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD>
<div align="center"><FONT face=verdana,arial,sans-serif color=#000000 size=1>Which is your favorite Flower?<BR>
</FONT>
<TABLE border=1 bordercolor="#333399">
<TBODY>
<TR>
<TD vAlign=top>
<INPUT type=radio value=F1 name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Daisy</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=F2 name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Rose</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=F3 name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Tulip</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<input type=radio value=F4 name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Lily</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=F5 name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Orchid</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=F6 name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Lilac</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=F7 name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Other</FONT></TD>
</TR>
</TBODY>
</TABLE>
<BR>
</div>
</TD>
</TR>
</TBODY>
</TABLE>
</th>
<th scope="col">
<TABLE width=123 border=1 cellPadding=4 cellSpacing=0 bordercolor="#333399" bgColor=#ddeeff>
<TBODY>
<TR>
<TD bgColor=#5588cc>
<TABLE width="100%" border=1 cellPadding=0 cellSpacing=0 bordercolor="#FFFFFF">
<TBODY>
<TR>
<TD align=middle>
<div align="center"><FONT face=verdana,arial,sans-serif color=#ffffff
size=2><B>My Favorites</B></FONT></div>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD bordercolor="#333399">
<div align="center"><FONT face=verdana,arial,sans-serif color=#000000 size=1>Which is your favorite Month?</FONT> </div>
<TABLE border=1 align="center" bordercolor="#333399">
<TBODY>
<TR>
<TD vAlign=top>
<input type=radio value=M1 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>January</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M2 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>February</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M3 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>March</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M4 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>April</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M5 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>May</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M6 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>June</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M7 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>July</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M8 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>August</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M9 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>September</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<input type=radio value=M10 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>October</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M11 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>November</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=M12 name=Month>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>December</FONT></TD>
</TR>
</TBODY>
</TABLE>
<BR>
</TD>
</TR>
</TBODY>
</TABLE>
</th>
<th scope="col">
<TABLE width=123 border=1 cellPadding=4 cellSpacing=0 bordercolor="#333399" bgColor=#ddeeff>
<TBODY>
<TR>
<TD bgColor=#5588cc>
<TABLE width="100%" border=1 cellPadding=0 cellSpacing=0 bordercolor="#FFFFFF">
<TBODY>
<TR>
<TD align=middle>
<div align="center"><FONT face=verdana,arial,sans-serif color=#ffffff size=2><B>My Favorites</B></FONT></div>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD bordercolor="#333399">
<div align="center"><FONT face=verdana,arial,sans-serif color=#000000 size=1>Which is your favorite sport?<BR>
</FONT>
<TABLE border=1 bordercolor="#333399">
<TBODY>
<TR>
<TD vAlign=top>
<INPUT type=radio value=S1 name=Sport>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Football</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=S2 name=Sport>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Bowling</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=S3 name=Sport>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Baseball</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=S4 name=Sport>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Hockey</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=S5 name=Sport>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Basketball</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=S6 name=Sport>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Soccer</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=S6 name=Sport>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Other</FONT></TD>
</TR>
</TBODY>
</TABLE>
<!-- Begin SPRINKS Code -->
<!-- End SPRINKS Code -->
</div>
</TD>
</TR>
</TBODY>
</TABLE>
</th>
</tr>
</table>
<br>
<table width="100%" cellspacing="5" cellpadding="5">
<tr>
<th scope="col">
<INPUT type=submit value="Submit Vote" name=poll_submit>
</th>
</tr>
</table>
<br>
<br>
<br>
<br>
<br>
<br>
<!-- content - Partner "default.partner" - File "poll_wizard/poll_source.htm" -->
<!-- Begin Poll Code -->
<br>
<br>
</FORM>
</body>
</html>
feyd | Please use[/syntax]Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Oct 10, 2006 1:28 pm
by feyd
The code you have that accesses, both INSERT and SELECT queries, the MySQL database.
Posted: Tue Oct 10, 2006 1:39 pm
by Elle0000
I am completely lost. I have nothing written that uses INSERT and SELECT queries.
I have nothing else. I guess that I am really lost on this concept.
Where should those commands be in the PHP script?
Below is the entire PHP script thus far.
Code: Select all
<html>
<head>
<title>Your Favorites</title>
<style type="text/css">
<!--
.style1 {
color: #333399;
font: bold 24px Arial;
text-align: center;
}
.style2 {
color: #333399;
font: bold 14px Arial;
}
.style5 {
font-size: 16px;
color: #330099;
font-family: Arial;
}
(resizable=yes,width=450,height=620)
}
-->
</style>
</head>
<body>
<form action="Poll.html" method="get">
<p class="style1">Your Favorites !</p>
<strong>
<p class="style5"> Thank you participating in this poll. <br>
If any items are incomplete, please hit the back button and complete your submission. </p> </strong>
<br>
<?php
if ( $Flower == "" ) {
$error=true;
echo "Please vote for your favorite flower.";
} else {
echo "Your favorite flower is the: $Flower."; }
?>
<br><br>
<?php
if ( $Month == "" ) {
$error=true;Vote for your favorite month.";
} else {
echo "Your favorite month is: $Month."; }
?>
<br><br>
<?php
if ( $Sport== "" ) {
$error=true;
echo "Please vote for your favorite sport.";
} else {
echo "Your favorite sport is: $Sport."; }
?>
Below are the results for each Month option:<br>
<br>
<br>
<br>
<br>
<br>
<?php
$Jantotal=0
While ($Month=M1) }
$Jantotal=sum($M1); }
$JanPercent=($Jantotal/(sum($M1));}
echo $JanPercent of people voted for January
"There was a total of $Jantotal votes"
?>
<input type="Submit" value="BACK" name="Submit">
<br>
<p class="style5"> <strong>Thanks for your time.</strong> </p>
</form>
</body>
</html>
Posted: Tue Oct 10, 2006 2:36 pm
by Elle0000
I don't understand PHP enough to code it like that. I'm posting because I have no clue.
It's a foreign language to me. The best analogy I can give is: I can't diagram a sentence if I can't read the words. I don't know how to structure this type of code.
I'm sorry if it wasn't done correctly. I'm desperate to understand.