Need a little nudge in the right direction...

Discussion in 'PHP' started by PHPScriptingServices, Oct 17, 2009.

  1. #1
    So i created a quiz but i need some help to solve a problem I am having... I have the quiz right now so that it saves the answers but what I would like to do is take all of the answers and determine which one was chosen more then the other to get the result...

    For example...

    What color do you prefer:

    -yellow
    -blue
    -red
    -black

    and the value to each option would be a1, a2, a3, a4...

    so what I am looking to do is say there is 5 questions and someone chooses a1 3 times and a3 2 times then there result would be a1... so I need to find a PHP snipit that will count the results and determine which one has been chosen the most and print it out...

    Anyone have any ideas or anything like this?
    Any help at this point would be appreciated...
     
    PHPScriptingServices, Oct 17, 2009 IP
  2. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #2
    PHP cant help for sure! PHP is server sided and I think that JavaScript/AJAX can help you.
     
    astrazone, Oct 17, 2009 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Do you mean you want to ask the same question multiple times and find which is the most popular or do you want a script that has multiple questions on one page and you want to know from options 1 - 5 which number is the most answered?
     
    JAY6390, Oct 17, 2009 IP
  4. PHPScriptingServices

    PHPScriptingServices Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No... Let me explain a little bit better for you to understand...

    I have a quiz that I have created... I am looking to create the results page now to tally up the result... there are 6 questions to the quiz and each question will have 4 multiple choice options... each multiple choice option will have the value of a1-4 which will be the same for every question.... Now since there are 6 questions what I al looking to do is make some kind of php script which will look at all the answers and for example say someone choose a4 on 5 of the questions and choose a1 on one of the questions then I will need php to check this and then see that a4 was choosen the most so it will print out the result for a4...

    If someone has any ideas on how I can further more do this in php then please can you help me out...
     
    PHPScriptingServices, Oct 17, 2009 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Submit all the values to php as an array of values then use array_count_values to tally them all up and then use asort to sort the array, and use the last value's key
     
    JAY6390, Oct 17, 2009 IP
  6. PHPScriptingServices

    PHPScriptingServices Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Do you have any examples just off hand... There are many ways to do this using an array but maybe the way you are thinking of might be a bit easier then what came to my mind...
     
    PHPScriptingServices, Oct 17, 2009 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I don't. I've given you the steps above of exactly what I was thinking. If you want me to make you a script it would be chargeable (PM me if you do)
     
    JAY6390, Oct 17, 2009 IP
  8. PHPScriptingServices

    PHPScriptingServices Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Okay... Thats fine... I have taken your advice so far and seems to be alright... If I run into any further problems then I will be sure to shoot you off a PM... Thanks for your assistance...
     
    PHPScriptingServices, Oct 17, 2009 IP
  9. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    No problem, good luck :)
     
    JAY6390, Oct 17, 2009 IP
  10. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #10
    If this result is for single user, the solution will work perfect. But if you want to choose answer using the logic you mentioned for the answers given by multiple users, then it better be taken from database where you have stored all the answers.

    I am not sure if I have got it right, but hoping to hear from you that the problem is sorted out :)
     
    mastermunj, Oct 18, 2009 IP