Page 1 of 1

How to create a Poll with php...

Posted: Sun Jun 26, 2005 12:39 pm
by kanenas.net
Hello to all php-programmers !!!

My problem is that I want to create a Poll with PHP in my site

www.kanenas.net

and I could use your help...

I am using SimplePhpBlog and I want to put a Poll in the menu of my home page on the right. All ideas or thoughts would be very helpful !!!

Thanks in advance for your help !!!
:P

Posted: Sun Jun 26, 2005 2:31 pm
by shiznatix
a poll in php is really easy to make but if you go to http://www.hotscripts.com then im sure you can find somthing you don't have to make

Thanks...

Posted: Mon Jun 27, 2005 2:43 am
by kanenas.net
Thanks shiznatix, I will do that !

kanenas.net

Posted: Mon Jun 27, 2005 5:35 am
by s.dot
if you want to make your own...

just make a database table
record the number of votes each option gets
divide each options total votes by the number of total votes

multiply that by 100, and that will give you a percentage. You can then display the results.

A really neat trick if you want to use graphical bars to show the percentage is to make a small bar, maybe 5 px wide

then in your html have a table cell 100 pixels wide. and have the image width = $percent

The begining...

Posted: Mon Jun 27, 2005 6:38 am
by kanenas.net
This is how I will begin...

Code: Select all

<form method=\&quote;post\&quote; action=\&quote;poll.php\&quote;> 
		<p><font size=\&quote;2\&quote; face=\&quote;Verdana\&quote;>Who is your favorite browser?</font></p> 
		<font face=\&quote;Verdana\&quote;><input type=\&quote;radio\&quote; name=\&quote;browser\&quote; value=\&quote;Firefox\&quote;></font><font size=\&quote;2\&quote; face=\&quote;Verdana\&quote;>Firefox</font><br>
		<font face=\&quote;Verdana\&quote;><input type=\&quote;radio\&quote; name=\&quote;browser\&quote; value=\&quote;InternetExplorer\&quote;></font><font size=\&quote;2\&quote; face=\&quote;Verdana\&quote;>Internet Explorer</font><br> 
		<font face=\&quote;Verdana\&quote;><input type=\&quote;radio\&quote; name=\&quote;browser\&quote; value=\&quote;Mozilla\&quote;></font><font size=\&quote;2\&quote; face=\&quote;Verdana\&quote;>Mozilla</font><br> 
		<font face=\&quote;Verdana\&quote;><input type=\&quote;radio\&quote; name=\&quote;browser\&quote; value=\&quote;Netscape\&quote;></font><font size=\&quote;2\&quote; face=\&quote;Verdana\&quote;>Netsacpe</font><br>
		<font face=\&quote;Verdana\&quote;><input type=\&quote;radio\&quote; name=\&quote;browser\&quote; value=\&quote;Opera\&quote;></font><font size=\&quote;2\&quote; face=\&quote;Verdana\&quote;>Opera</font><br> 
		<font face=\&quote;Verdana\&quote;><input type=\&quote;radio\&quote; name=\&quote;browser\&quote; value=\&quote;Other\&quote;></font><font size=\&quote;2\&quote; face=\&quote;Verdana\&quote;>Other</font><br><br> 
		<input type=\&quote;submit\&quote; name=\&quote;choice\&quote; value=\&quote;Submit\&quote;> 
		</form>

to be continued with the poll.php file !!!


kanenas.net

d11wtq |

Code: Select all

 tags... I say! [ code]  :D [/color]

Posted: Tue Jul 26, 2005 7:35 am
by kanenas.net
This is how it continues...

1.Create a MySQL database e.g "db_name".
2.Create a php-file with the name poll.php.
3.Fill in the proper "localhost","username","password","db_name"... things with your settings from the database.

Code: Select all

<?php
//connect to server and select database
$conn = mysql_connect(&quote;localhost&quote;, &quote;username&quote;, &quote;password&quote;) or die(mysql_error());
mysql_select_db(&quote;db_name&quote;,$conn) or die(mysql_error());

if (isset($_POST&#1111;'browser']) && !empty($_POST&#1111;'browser']))
mysql_query(&quote;UPDATE browser SET tally=tally+1 WHERE name='{$_POST&#1111;'browser']}'&quote;);

$result = mysql_query(&quote;SELECT name, tally FROM browser&quote;) or die(mysql_error());

$num_rows = mysql_num_rows($result);
?>
<html>
<head>
<meta http-equiv=&quote;Content-Language&quote; content=&quote;en-us&quote;>
<title>Your Home-Page :: Poll</title>
<link rel=&quote;shortcut icon&quote; href=&quote;interface/favicon.ico&quote;>
<link href=&quote;/themes/modern/style.css&quote; rel=&quote;stylesheet&quote; type=&quote;text/css&quote;>
</head>
<body>
<br>
<br>
<br>
<br>
<center>
<h2>Here are the results !!!</h2>
<h3>Number of browsers: <?PHP echo $num_rows; ?></h3>
<table width=&quote;300&quote; border=&quote;1&quote;>
<?PHP
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td width=&quote;80&quote;>
<b><?PHP echo $row&#1111;'name']; ?></b>
</td>
<td width=&quote;50&quote;>
<b><?PHP echo $row&#1111;'tally']; ?></b>
</td>
</tr>
<?PHP
}
?>
</table>
<br>
<a href=&quote;http://www.your-homepage.com&quote;>Go back to <b>your-homepage.com</b></a>
</center>
</body>
</html>
...and it worked !!!

TODO : I will try not to use a database (MySQL, MS-SQL or other !!!)

Any suggestions could be very helpful !