im new to php and i need help with polls

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

gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

im new to php and i need help with polls

Post by gaogier »

can someone help me to make a working poll that will go with my site http://runehints.com
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

what is it with runescape...?

Anyway, it depends on whether you want to use MySQL. If so, create a table and have it update when the form is submitted. Otherwise, you can just use a text file, where the data could be stored as:
##|##|##|##|##|##
where ## is the number of votes.

Code: Select all

$data = file_get_contents('name.poll');
$data = explode("|",$data);
$data[$_POST['vote']]++;
$data = implode("|",$data);
$file = fopen('name.poll','w');
fwrite($file,$data);
fclose($file);
pretty sure I got that right...
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

http://www.runehints.com/poll.php

go there and thats what i get

i used one from somehting on google search


heres what i got

Code: Select all

<?php
$db=&quote;mydatabase&quote;;
$link = mysql_connect(&quote;localhost&quote;);
if (! $link) die(&quote;Couldn't connect to MySQL&quote;);
mysql_select_db($db , $link) or die(&quote;Couldn't open $db: &quote;.mysql_error());
	

Contents
Free PHP MySQL Tools

Introduction to PHP MySQL

Connecting to the Server

Creating a Database

Create a Table

Adding Data

Displaying Data

Editing Table Data

Altering Tables

Advanced
Multiple Selection Forms
/*loop through the selected fields - multiple if using checkbox*/
foreach ($check as $value){
mysql_query(&quote;UPDATE simplepoll SET number=number+1 WHERE code LIKE '$value'&quote;);
}
//select the new updated values
$result = mysql_query( &quote;SELECT color,number FROM simplepoll&quote; ) or die(&quote;SELECT Error: &quote;.mysql_error());
//display the updated results
$num_rows = mysql_num_rows($result);
print &quote;<html><head><style type=text/css>
#poll{border-top :solid #004f9d 2px;border-left :solid #004f9d 2px} #poll tr td {border-bottom :solid #004f9d 2px;border-right :solid #004f9d 2px} #poll tr td {font-family: Small Fonts;font-style : normal ;font-size : 7pt; font-weight :bold } h3{font-family: Arial;font-style : normal ;font-size : 9pt; font-weight :bold;text-align : center; color :#FFFFFF;background-color :#004f9d }</style>
</head>
<body>
<table width=100%><tr valign=top><td>\n&quote;;
print &quote;<table ID=poll cellspacing=0 cellpadding=5 width=125 >\n&quote;;
print &quote;<tr valign=top><td colspan=2 bgcolor=#004f9d><h3>Other users chose these options.</h3></td></tr>\n&quote;;
while ($get_info = mysql_fetch_row($result)){
print &quote;<tr>\n&quote;;
foreach ($get_info as $field )
print &quote;\t<td>$field</td>\n&quote;;
print &quote;</tr>\n&quote;;
}
print &quote;</table>
</tr></table></body></html>\n&quote;;
mysql_close($link);
?>


and the form tables

Code: Select all

<dt><input type=&quote;checkbox&quote; name=&quote;check&#1111;]&quote; value=&quote;c1&quote;>

Place style sheets in head section:
#poll{ ;border-style : solid ;border-color : #004f9d ;border-width : 2px}
#poll tr td dt{font-family: Small Fonts;font-style : normal ;font-size : 7pt; font-weight :bold }


<table ID=&quote;poll&quote; width=&quote;125&quote; cellpadding=&quote;2&quote; cellspacing=&quote;0&quote; border=&quote;0&quote;>
<tr align=&quote;center&quote; valign=&quote;top&quote;>
<td align=&quote;left&quote; colspan=&quote;1&quote; rowspan=&quote;1&quote;>
<h4>Select your favorite color.</h4>
<form method=&quote;POST&quote; action=&quote;simple-poll.php&quote;>
<dl>
<dt><input type=&quote;radio&quote; name=&quote;check&#1111;]&quote; value=&quote;c1&quote;>Red<br>
<dt><input type=&quote;radio&quote; name=&quote;check&#1111;]&quote; value=&quote;c2&quote;>Green<br>
<dt><input type=&quote;radio&quote; name=&quote;check&#1111;]&quote; value=&quote;c3&quote;>Blue<br>
<dt><input type=&quote;radio&quote; name=&quote;check&#1111;]&quote; value=&quote;c4&quote;>Yellow<br>
</dl>
<input type=&quote;submit&quote; value=&quote;Results&quote;><input type=&quote;reset&quote;>
</form>
</td></tr></table>
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

comon i need your help here
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

what's not happening?

The first block of code the should make the database connection but there is no query to get either what you want to display in the poll or to update a table with what ever the user selects.
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

there is something on msql and its poll_data database so what do i do with this?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

i'm missing something here.

What you want is that when some one clicks on one of the images at the bottom of the page in the desclaimer section you want that to register as a vote for the site?

Or do you want a seperate list that people will choose from.

Is the db holding the votes being hosted by you or is it going to be by someone else?
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

i want a poll so i can put questions on it and people can answer them
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

the one you showed simple-poll.php will do the job but it doesn't look that good to me.
http://www.hotscripts.com/PHP/Scripts_a ... nd_Voting/
has some more to try and have readme.txt files with them to help you install them.
Some are even free.
try those out to see if any work for you.

if not it wouldn't be to hard to create your own if that is what you wished, depending on the options that you want.
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

from what i can tell they wont go with the site
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

try easypoll
its not very advanced but it might serve the purpose and you can easily modify the look and feel of questionaire, its just simple html and some special tags. read the readme.html that comes with it.
sounds simple enough to me.
One drawback that jumped out at me was the limit of five questions but im sure that could be overcome.

http://www.phpwebscripts.com/free_scrip ... _poll.html
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

its really confusing it seems like it dosnt want to work
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What are you asking here? For some one to make a poll for you? --or-- are you actually going to take the time and understand how most polls and done and create your own?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

you might have to get the person who developed your site to install it for you then.
no judgement but it you built your site then you probably could get it running.

the instructions are fairly easy for some one who has used php, mysql and an ftp client.
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

Jcart wrote:What are you asking here? For some one to make a poll for you? --or-- are you actually going to take the time and understand how most polls and done and create your own?

i manily want someone to tell me how i can make one that will go with my sites design but i dont know alot of php
Post Reply