|
-
Apr 5th, 2007, 11:42 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED]Help with Arrays
I am trying to figure out what the best way to do the following with an array.
I am writing a quiz program that stores the missed questions in a database field in the following format: 1,2,3,4,5
What I am trying to do is pool the results and display them. My goal is to get two arrays that correspond with each other. one to store the actual question number and the other to store how many times that particular question is missed. Each array being respective to each other.
Any ideas? I'm lost
Last edited by zalez; Apr 7th, 2007 at 03:26 PM.
Reason: Resolved
-
Apr 5th, 2007, 12:30 PM
#2
Re: Help with Arrays
I am kinda lost too 
Are you putting all the scores into a database based on what user took the quiz? if so then all you need to do is pull all the scores from the db by the users name.
My usual boring signature: Something
-
Apr 5th, 2007, 02:22 PM
#3
Thread Starter
Hyperactive Member
Re: Help with Arrays
 Originally Posted by zalez
I am writing a quiz program that stores the missed questions in a database field in the following format: 1,2,3,4,5
I am storing in a database and retrieving the results is not a problem.
 Originally Posted by zalez
What I am trying to do is pool the results and display them. My goal is to get two arrays that correspond with each other. one to store the actual question number and the other to store how many times that particular question is missed. Each array being respective to each other.
I need to figure out how to go through the results (which would like like this: 1,2,3,4,5) and add up how many times the number 1, 2, 3 ..... and so on, appear. And then store that info into an array.
Let's say 3 ppl take this quiz:
3 ppl miss question #2 and #3
1 person misses #4
I would then grab my missed questions results from the db which the results would look something like this:
Person1: 2,3
Person2: 2,3
Person3: 2,3,4
I need to count how many times each number shows up and store them in an array.
array #1 would be the missed questions (2,3,4)
array #2 would be how many times each question was missed (3,3,1)
I hope this makes more sense.
Last edited by zalez; Apr 5th, 2007 at 02:25 PM.
-
Apr 5th, 2007, 11:13 PM
#4
Addicted Member
Re: Help with Arrays
You can try doing something like this:
Code:
$missed = array();
//Index will be the question number, Value will be the number of times it was missed.
foreach( person who took test){
foreach(question_missed by the person){
if (array_key_exists(question_number,$missed)){
$missed[question_number]++;
}
else{
$missed[question_number] = 1;
}
}
}
-
Apr 6th, 2007, 01:10 AM
#5
Re: Help with Arrays
You are better off creating a separate table to store the missed questions. You can then use the SQL aggregate functions to count how many muach quicker than calculating it in the application.
-
Apr 7th, 2007, 03:26 PM
#6
Thread Starter
Hyperactive Member
Re: Help with Arrays
Thank you both for your help and suggestions. I got it to work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|