Poll...

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
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Poll...

Post by Zoram »

I am trying to do all the programming for the web site that I am doing and was wondering how the best way to program a poll would be...
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

MySQL or Flat(text) Files?
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

I'll be using MySQL
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

you'll want to have two tables...

one for the options of the poll, two columns - "option" and "id" - id will be auto_increment

one for the votes, two columns one for "oid" and one for "count"

the script will grab the options out of the options table, and you will vote...the script will do a query like "SELECT * FROM votes WHERE oid = '$vote'" (vote being the id of what they voted for..). it will do a mysql_num_rows, and if it returns zero it will do an INSERT statement inserting something into the table. if it returns otherwise you will do an UPDATE adding one to the "count"... you will then set a cookie so it won't be done over and over (you need to check for the cookie at the begining)... then just a little math to display the pie chart/bar graph or whatever.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

here is a great poll tutorial I found on devshed, I used it this week and it works :o

http://www.devshed.com/Server_Side/PHP/ ... page1.html
Post Reply