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 !!!

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=\"e;post\"e; action=\"e;poll.php\"e;>
<p><font size=\"e;2\"e; face=\"e;Verdana\"e;>Who is your favorite browser?</font></p>
<font face=\"e;Verdana\"e;><input type=\"e;radio\"e; name=\"e;browser\"e; value=\"e;Firefox\"e;></font><font size=\"e;2\"e; face=\"e;Verdana\"e;>Firefox</font><br>
<font face=\"e;Verdana\"e;><input type=\"e;radio\"e; name=\"e;browser\"e; value=\"e;InternetExplorer\"e;></font><font size=\"e;2\"e; face=\"e;Verdana\"e;>Internet Explorer</font><br>
<font face=\"e;Verdana\"e;><input type=\"e;radio\"e; name=\"e;browser\"e; value=\"e;Mozilla\"e;></font><font size=\"e;2\"e; face=\"e;Verdana\"e;>Mozilla</font><br>
<font face=\"e;Verdana\"e;><input type=\"e;radio\"e; name=\"e;browser\"e; value=\"e;Netscape\"e;></font><font size=\"e;2\"e; face=\"e;Verdana\"e;>Netsacpe</font><br>
<font face=\"e;Verdana\"e;><input type=\"e;radio\"e; name=\"e;browser\"e; value=\"e;Opera\"e;></font><font size=\"e;2\"e; face=\"e;Verdana\"e;>Opera</font><br>
<font face=\"e;Verdana\"e;><input type=\"e;radio\"e; name=\"e;browser\"e; value=\"e;Other\"e;></font><font size=\"e;2\"e; face=\"e;Verdana\"e;>Other</font><br><br>
<input type=\"e;submit\"e; name=\"e;choice\"e; value=\"e;Submit\"e;>
</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("e;localhost"e;, "e;username"e;, "e;password"e;) or die(mysql_error());
mysql_select_db("e;db_name"e;,$conn) or die(mysql_error());
if (isset($_POSTї'browser']) && !empty($_POSTї'browser']))
mysql_query("e;UPDATE browser SET tally=tally+1 WHERE name='{$_POSTї'browser']}'"e;);
$result = mysql_query("e;SELECT name, tally FROM browser"e;) or die(mysql_error());
$num_rows = mysql_num_rows($result);
?>
<html>
<head>
<meta http-equiv="e;Content-Language"e; content="e;en-us"e;>
<title>Your Home-Page :: Poll</title>
<link rel="e;shortcut icon"e; href="e;interface/favicon.ico"e;>
<link href="e;/themes/modern/style.css"e; rel="e;stylesheet"e; type="e;text/css"e;>
</head>
<body>
<br>
<br>
<br>
<br>
<center>
<h2>Here are the results !!!</h2>
<h3>Number of browsers: <?PHP echo $num_rows; ?></h3>
<table width="e;300"e; border="e;1"e;>
<?PHP
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td width="e;80"e;>
<b><?PHP echo $rowї'name']; ?></b>
</td>
<td width="e;50"e;>
<b><?PHP echo $rowї'tally']; ?></b>
</td>
</tr>
<?PHP
}
?>
</table>
<br>
<a href="e;http://www.your-homepage.com"e;>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 !