Jump to content

[SOLVED] Need to keep track of how many times a question has been answered wrong


rondog

Recommended Posts

I am making a quiz in flash and I know how to send variables to PHP to insert stuff into the database, however my client wants to be able to see how many times a question has been answered incorrectly so in flash, every time they answer a question, the question number is inserted into an array. If I trace (echo in php) out the array Ill get something like this:

 

2,5,8,6,2,5,2

 

meaning they 2, 5, 6 and 6 initially, reanswered and missed 2 and 5 again, reanswered and missed 2 again before getting all of them right. So thats why you see duplicates. My question is, when I send that array to PHP..say:

 

$wrongAnswers = $_POST['the wrong answer array from flash'];

 

how would I separate all these values and insert them to the DB? I would have to increment whatever number is already in the DB...for example if question2 field was at 35, after this user submitted his/her data it would then be 38. Get it?

 

I know what explode does..I believe I can separate at the comma, but how do I made then individual values so like I said question2 field would be incremented 3 times?

Link to comment
Share on other sites

That is indeed what explode does .. if you get it as a string with commas as above, you can do like this

 

$wrongAnswers_arr = explode(',', $wrongAnswers);
$counts = array();
foreach ($wrongAnswers_arr as $wa) {
  print "Processing wrong answer for question $wa\n";
  # Do whatever with $wa
  $counts[$wa]++;
}

 

Is that what you're looking for?  If you want to aggregate the values before writing to the database you can create an array of counts, as I've shown above.

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.