Welcome to WebmasterWorld Guest from 54.211.136.250

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Newbie needs help with polling app

   
8:57 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



Hi Guys,

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:

High Priority:
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

Medium Priority:
1) Use vBulletin's 'member' profile to authenticate users (I'm pretty sure I can do this myself)

Low Priority:
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)
b) vbulletin_userid
c) vote_date
d) Q1_answer_1
e) Q1_answer_2
f) Q1_answer_3
g) Q2_answer_1
h) Q2_answer_2
i) Q3_answer_1
...

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.

Thanks,

Stephen

10:11 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sorry I can't help you with the PHP scripting, but you have probably been looking at the wrong scripts if you have been looking at "polls/polling" scripts. Look for online survey scripts as it sounds like that's what you need.
11:07 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



You're right, I haven't searched for survey scripts. I'll do that as well.

Thanks for the suggestion,

Stephen

11:48 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



Ok, found my answer. Thanks again for the suggestion.

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.

Thanks,

Stephen

2:46 am on Dec 30, 2008 (gmt 0)

10+ Year Member



Ok, ignore the code in the last post... it should be something like this... :)

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');

...