Jump to content

[SOLVED] Query string comparison and addition


jameson9

Recommended Posts

Hey guys,

I am new here and new to both PHP and MYSQL so please bear with me.

I have a table in my db set up for a quiz and answers and want to compare the parsed query string against the answers in the table, then total them.

The table has a field for the quiz id# and then 20 separate fields each containing an integer between 1-4 corresponding to the correct answer on the multiple choice quiz. I want to assign a value of 5 for each field so that the sum total = 100.

When a query string is passed, I want to compare the string against the answers in the table, and whichever ones are equal to the values in the table, total them up to get a percentage score.

Any ideas as to how to do this as simply as possible? Am I going the wrong way about it altogether?

 

Link to comment
Share on other sites

How about this structure?

 

quiz_id  question  answer

1          1          3

1          2          4

1          3          1

 

It'll be easier to work with than having one column for each question.  In general, using columns for 20 things which are only distinguished by number is a bad idea.  It's better to put them in rows, and put the distinguishing number in a single column.

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.