How Do I Store Results From a Poll and Display Them?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Elle0000
Forum Newbie
Posts: 6
Joined: Tue Oct 10, 2006 12:30 pm

How Do I Store Results From a Poll and Display Them?

Post by Elle0000 »

feyd | Please use

Code: Select all

,

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]


I need to troubleshoot PHP code to store the results of a poll, and to display the results. I have started the code but am really confused how to properly use the CREATE DATABASE, CREATE TABLE, INSERT and SELECT statements.
I need help with this, as well as how to display the results in a similar fashion to the below:

Your favorite flower is the Rose. 

There are 500 total votes. 

Rose received 10% of the total vote. 
Daisy received 20% of the total vote. 
Other received 70% of the total vote.

Please assist me with structuring the code, and/or direct me to a similar poll on the Internet, so that I may actually see code that works. Examples of how to use the above statements would be very helpful.

[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=Pollresults2.php method=post 
target="">
<table width="33%" border="1" align="center" bordercolor="#333399">
<tr bordercolor="#333399">
<th scope="col">
<TABLE width=133 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=Daisy 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=Rose 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=Tulip 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=Lily 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=Orchid 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=Lilac 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=Other 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>
<br>
<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>
</FORM>
</body>
</html>
[/syntax]

Code: Select all

</head> 
<body> 
<form action="Poll2.html" method="get"> 
<style type="text/css"> 
<!-- 
.style1 { 
color: #333399; 
font: bold 24px Arial; 
text-align: center; 

--> 
</style> 
<p class="style1">Le Fleur!</p> 
<strong><p class="style5"> Thank you for your vote. Below are the results. 
<br> 
If you did not vote, please hit the back button and do so. </p> </strong> 
<br> 
<?php 
CREAT TABLE votes {
Response VARCHAR (6){ ;

insert into votes (response) values (" + selectedFlower + ")
select  (sum( response) /count(*))*100 from votes group by response
?> 
<?php 
if ( $Flower == "" ) { 
$error=true; 
echo "Please vote."; 
} else { 
echo "Your favorite flower is the: $Flower."; } 
?> 
<br><br> 
<?php 
$query="select (sum( response) /count(*)) as '% Votes'; } 
$result=mysql_query($query); 
$num=mysql_numrows($result); 
$i=0; 
echo "The Poll Results Are:" ; } 
while ($i < $num) { 
?> 
<?php 
$percentageVotes = mysql_result($result,$i,"% Votes"); 
$flowerName = mysql_result($result,$i,"response"); } 
<?php 

if( $flowerName = 'Rose'){ 

$flowerName = 'Rose'; 

}else if($flowerName = 'Daisy){ 

$flowerName = 'Daisy'; 

}else if($flowerName = 'Tulip){ 

$flowerName = 'Tulip'; 

}else if($flowerName = 'Lily'){ 

$flowerName = 'Lily'; 

}else if($flowerName = 'Orchid){ 

$flowerName = 'Orchid'; 

}else if($flowerName = 'Lilac){ 

$flowerName = 'Lilac'; 

}else if($flowerName = 'Other'){ 
$flowerName = 'Other'; 
?> 
<?php 
select (count( response) /count(*)) as '% Votes' </td><td>$flowerName </td></tr>"; } 
$i++; 
} 
?> 
<br><br> 
<input type="Submit" value="BACK" name="Submit"> 
<br> 
<p class="style5"> <strong>Thanks again for your time.</strong> </p> 
</form> 
</body> 
</html>

feyd | Please use

Code: Select all

,

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]
Post Reply