Results 1 to 6 of 6

Thread: [RESOLVED]Help with Arrays

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Question [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

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: Help with Arrays

    Quote 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.

    Quote 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.

  4. #4
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    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;
        }
      }
    }

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    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
  •  



Click Here to Expand Forum to Full Width