jameson9 Posted February 28, 2007 Share Posted February 28, 2007 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 https://forums.phpfreaks.com/topic/40598-solved-query-string-comparison-and-addition/ Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 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 https://forums.phpfreaks.com/topic/40598-solved-query-string-comparison-and-addition/#findComment-196589 Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 Agreed -- you may want to read the database normalization sticky that addresses this issue. Link to comment https://forums.phpfreaks.com/topic/40598-solved-query-string-comparison-and-addition/#findComment-196872 Share on other sites More sharing options...
jameson9 Posted March 1, 2007 Author Share Posted March 1, 2007 Ok, thanks for the advice guys. I knew it looked a bit stupid when I set up the table but seemed like a good idea at the time! Link to comment https://forums.phpfreaks.com/topic/40598-solved-query-string-comparison-and-addition/#findComment-197375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.