rondog Posted November 30, 2007 Share Posted November 30, 2007 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? Quote Link to comment Share on other sites More sharing options...
btherl Posted November 30, 2007 Share Posted November 30, 2007 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. Quote Link to comment Share on other sites More sharing options...
rondog Posted November 30, 2007 Author Share Posted November 30, 2007 dude ur awesome thanks..thats exactly what i needed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.