vistavision Posted May 8, 2014 Share Posted May 8, 2014 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,Q1CQuestion 2:Q2A,Q2B,Q2CAfter 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 = 1Product2 = 1 + 1 = 2Product3 = 0 + 0 = 0Product4 = 1 + 0 = 1Product 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 Quote Link to comment https://forums.phpfreaks.com/topic/288351-making-a-quizelection-vote-script-any-ideas/ Share on other sites More sharing options...
vistavision Posted May 10, 2014 Author Share Posted May 10, 2014 Anybody? I really need to know if this is the way to go. Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/288351-making-a-quizelection-vote-script-any-ideas/#findComment-1479013 Share on other sites More sharing options...
davidannis Posted May 10, 2014 Share Posted May 10, 2014 (edited) 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 May 10, 2014 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/288351-making-a-quizelection-vote-script-any-ideas/#findComment-1479020 Share on other sites More sharing options...
vistavision Posted May 11, 2014 Author Share Posted May 11, 2014 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! Quote Link to comment https://forums.phpfreaks.com/topic/288351-making-a-quizelection-vote-script-any-ideas/#findComment-1479113 Share on other sites More sharing options...
davidannis Posted May 12, 2014 Share Posted May 12, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/288351-making-a-quizelection-vote-script-any-ideas/#findComment-1479212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.