Welcome to WebmasterWorld Guest from 18.104.22.168
I've been working with MySQL and PHP for the last 2 weeks (yep, two whole weeks of experience) and I'm stuck trying to figure out what script to leverage to build a custom polling app. Most of the scripts I have seen so far generally have stuff I don't want or isn't sufficient for my needs and maybe I'm saying this because I don't know how to leverage what's available out there (e.g., ability to setup multiple polls, polls only asking one question, IP based authentication to prevent multiple votes, ability for users to create polls, etc. are things I don't need): Following are my requirements:
1) I need *only* one poll with 10 questions (this can be hardcoded if that helps)
2) Each question will have 3-5 answers
3) Answers will be in selected using radio buttons
4) Use MySQL to store answers
1) Use vBulletin's 'member' profile to authenticate users (I'm pretty sure I can do this myself)
1) Ability for members to update their votes if they so choose (this would be a nice to have)
So far, my table looks like the following:
a) Id (primary key)
Most of the stuff out there seems to have one table for question and another for answers so my requirements are simpler in some ways but all of the scripts I've seen so far don't show how to do multiple questions per poll.
Also, if someone is kind enough to direct me on how to do this, I would really appreciate it. I'm a pretty fast learner (I think...) and would certainly appreciate the help.
Now the next question - is there a way to submit multiple updates in one query. Currently, I'm planning to do something like the following:
mysql_query("INSERT tbl_survey SET q1_answer_1=1, userid='$userid', item='$item' WHERE area='$q1_answer_1');
mysql_query("UPDATE tbl_survey SET q1_answer_2=1 WHERE userid='$userid' AND item='$item' AND area='$q1_answer_2');
mysql_query("UPDATE tbl_survey SET q1_answer_3=1 WHERE userid='$userid' AND item='$item' AND area='$q1_answer_3');
As you can see, the first query inserts the info and the following queries update the first insert. Obviously this can become quite cumbersome with 45 answers... Is there a simpler way of setting these into an array and executing one insert row all at once WHERE item='$item_nbr' and userid='$userid' ? Any help is appreciated.
mysql_query("INSERT tbl_survey SET q1_answer_1=1, userid='$userid', item='$item'');
mysql_query("UPDATE tbl_survey SET q1_answer_2=1 WHERE userid='$userid' AND item='$item');
mysql_query("UPDATE tbl_survey SET q1_answer_3=1 WHERE userid='$userid' AND item='$item');