This is the tutorial that will help you to create a basic poll, which is user log in based voting. In the other words, each user is entitled to vote for one time for that question. If the question changes, then they can vote again.
A lot of resources that I found from Internet are those teaching you how to create a poll but the voting is tracked by IP address. Each IP address is entitled to vote for that particular question. This is not the right way because they can just restart their modem (if they are using dynamic IP address) and try to vote again or if all employees in the company are using shared IP address, then only one people can vote.
Today I will let you know the fields that are required when creating polling table in MySQL. Next lesson only proceed to PHP coding.
MySQL: Tutorial On How To Create Polling Table?
You need to create 2 table, one is to store all the information about polling question and answer while the another one is to store the user voted option.
1. Create your table named tbl_poll.
i) You need to have question id, which uniquely identified each question. So, create the question id in your table. E.g, qst_ID, set the type to INT. Make is as your primary key.
ii) Next, you need another field for displaying the question. E.g, qst, set the type to TEXT.
iii) Create 4 fields in your table (assume the voting has 4 answer) to display the polling answers. E.g, ans1, ans2, ans3, ans4, set the type to TEXT.
iv) Next, create 4 option fields in your table to count the option (frequency of the option) that is chosen by users. I am going to teach you how to display the result in percentage value instead of number of people voted. E.g, opt1, opt2, opt3, opt4, set the type to INT.
v) Create 1 field to count the total number of 4 options (sum up the value of opt1, opt2, opt3, and opt4). E.g, votes, set the type to BIGINT.
vi) Next, create 1 field to set polling status (set it to 1 if you want the question to be displayed or else set it to 0). E.g, status, set the type to INT.
i) At first, you need to have user id, which uniquely identified each user. So, create the user id in your table. E.g, user_id, set the type to INT.
ii) Then, same as tbl_poll, create qst_id here too.
iii) Create 1 field to keep track the option (1, or 2, or 3, or 4) that is chosen by user. E.g, option, set the type value to INT.
*Make these 3 fields become primary key. (If you just make qst_id, means only that user with that user_id can vote for that question, other user has no right to vote)
To be continued…


By learning html on Aug 24, 2009 | Reply
very nice post