Jump to content

Making a quiz/election vote script, any ideas?


vistavision

Recommended Posts

Hi all,

 

I want to make a quiz but I'm stock in the process. I've created a form with radiobuttons with questions, so for example:

Question 1:
Q1A,Q1B,Q1C

Question 2:
Q2A,Q2B,Q2C

After visitors filled in the answers, the form post it to my results.php. This works perfectly. Now I have a MySQL database with:

 

+----------+--------+-----+-----+-----+-----+-----+-----+
| PRODUCT  |  BRAND | Q1A | Q1B | Q1C | Q2A | Q2B | Q2C |
+----------+--------+-----+-----+-----+-----+-----+-----+
|          |        |     |     |     |     |     |     |
| product1 | Apple  | 1   | 0   | 1   | 0   | 1   | 0   |
|          |        |     |     |     |     |     |     |
| product2 | HP     | 0   | 1   | 1   | 1   | 1   | 1   |
|          |        |     |     |     |     |     |     |
| product3 | Dell   | 0   | 0   | 0   | 0   | 1   | 0   |
|          |        |     |     |     |     |     |     |
| product4 | Compaq | 1   | 1   | 1   | 0   | 0   | 0   |
+----------+--------+-----+-----+-----+-----+-----+-----+

So if the user select Q1C in question A and Q2A in question B, I want to count all the values from the selected columns, so in this case:

Product1 = 1 + 0 = 1
Product2 = 1 + 1 = 2
Product3 = 0 + 0 = 0
Product4 = 1 + 0 = 1

Product 2 wins and is most relevant. I then want to show the top 3 on the page. In total I have about 20 questions and 400 products and I want to create a top 3 list, based on the selected answers.

 

I have a few questions:
1) Is this possible? Or are there better ways to make a election/voting script? Any examples?
2) How can I add the values from multiple columns together and make a total score for the visitor?

 

For example, I need something like this:

http://www.stemwijzer.nl/votematch2k2006/app.html

 

I really hope you guys can help me with this! I really want this!! Thanks so much in advance!!

 

Kind regards,

Mark

 

 

Link to comment
Share on other sites

1) Is this possible? Or are there better ways to make a election/voting script? Any examples?

Yes, it is possible. I might arrange the tables differently.

| PRODUCT  |  BRAND |Question    | Answer   
+----------+--------+------------+-----+-----+-----+-----+-----+
|          |        |            |     |     |     |     |     |
| product1 | Apple  | 1          | A
| product 1  Apple  | 2          |  B  |     |     |     |     |     |
...

You don't have to store the brand in every row (in fact you should pull it out). This allows you to have a different number of questions for each poll.

2) How can I add the values from multiple columns together and make a total score for the visitor?

 

I'd make an array with product as key.

then I would select those products where the answer was the same as the user's answer and increment the array as each question was answered. something like:

$query="SELECT * FROM mytablename where Q='question_id' and answer='$users_answer'";
$result=mysqli_query($link,$query)
while ($row=mysqli_fetch_assoc($result)){
   $score[{$row['product']}]+=1;
}
Edited by davidannis
Link to comment
Share on other sites

Hi davidannis,

 

Thanks for your great reply and for your help. Only I want it a little bit different I think. It's not that there is a right or wrong answer to the questions. I want to work with points. So if a user choose answer A for example, I want to add 2 points to all products, if they choose B, I want to add 3 points to all products etc. The points are different with each question. In the end, the product with the most points is number 1!

 

Please tell me how I can make this? I'm willing to learn and try things out, but I need to know how to start. I hope you can help me!

 

Thanks!!! Really appreciate it!

Link to comment
Share on other sites

Hi davidannis,

 

Thanks for your great reply and for your help. Only I want it a little bit different I think. It's not that there is a right or wrong answer to the questions. I want to work with points. So if a user choose answer A for example, I want to add 2 points to all products, if they choose B, I want to add 3 points to all products etc. The points are different with each question. In the end, the product with the most points is number 1!

 

Please tell me how I can make this? I'm willing to learn and try things out, but I need to know how to start. I hope you can help me!

 

Thanks!!! Really appreciate it!

What I did will add one point to each product for every answer that the user picks which agrees with the value for that product in the databases. "Adding 2 points to all products (I assume just those products that agree with the user's preference) for one question and 3 points to all products that agree with another question requires an additional field in the database that tells how many points a question is worth.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.