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?

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.