Pulling the right answer from MCQS system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • semanticnotion
    New Member
    • Sep 2010
    • 66

    #1

    Pulling the right answer from MCQS system

    I have a MCQS test application in which i have 3 tables e.g


    i) Subject (sub_code, subject)
    ii) Question (question_id,qu estion, rate/level, sub_code)
    iii) Answer (answer_id, answer, question_id)

    I added the subject in subject i added the relevant question and for that question i added relevant answer in answer table.

    If the user click on any option how can i know that the selected answer is right or wrong. OR
    how can i pull the right answer as out put from my database. Plz Help

    Thanks in advance
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    That depends on what determines the correct answer. In neither your Question table nor your Answer table is there any attribute defining which answer is correct. This should be defined on the question... Is that what the "sub_code" is?

    Comment

    • semanticnotion
      New Member
      • Sep 2010
      • 66

      #3
      kovik thanks for your response
      so where i should define the correct answer whether in question or answer table and in what manner plz help me

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Well, your question implied that this was already defined by this "MCQS" system.. Is this pre-built or did you make it?

        Comment

        • semanticnotion
          New Member
          • Sep 2010
          • 66

          #5
          No its not pre-build i want to make it
          i make these three tables and now i have some problem about the right answer i you have some idea about this plz help me its urgent or if need to know about my code i can upload that.

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            Then, you either have to define the correct answer in the question or in the answers. If it is possible to have more than one correct answer, then define it in the answers. If there will always be one correct answer, define it in the question. I would also add an "order" attribute to these items so that they can be reordered without changing their physical IDs.

            Code:
            # Subjects
            create table subjects (
                id int not null auto_increment,
                title varchar(255) not null,
            primary key (id));
            
            # Questions
            create table questions (
                id int not null auto_increment,
                subject_id int not null,
                correct_answer_id int,  # Add this if there's one correct answer
                order int not null default 0,
                question text not null,
            primary key (id));
            
            # Answers
            create table answers (
                id int not null auto_increment,
                question_id int not null,
                answer text not null,
                is_correct boolean default false,  # Add this if there can be multiple answers
            primary key (id));

            Comment

            • semanticnotion
              New Member
              • Sep 2010
              • 66

              #7
              Thanks for this kovik but where should i place the choices like a,b,c,d,e etc
              e.g
              Q 1 what is computer
              a: A computer is machine.
              b: A computer is mobile.
              c: A computer is fax.
              d: A computer is nothing. etc

              Comment

              • kovik
                Recognized Expert Top Contributor
                • Jun 2007
                • 1044

                #8
                In the answers table...

                So, the answers would be in the table like this:

                Code:
                insert into questions (id, subject_id, correct_answer_id, order, question) VALUES
                (1, 1, 1, 1, 'what is computer');
                
                insert into answers (id, question_id, answer) VALUES
                (1, 1, 'A computer is machine')
                (2, 1, 'A computer is mobile')
                (3, 1, 'A computer is fax')
                (4, 1, 'A computer is nothing');
                The IDs I've given are arbitrary, and generally shouldn't be set manually.

                Comment

                • semanticnotion
                  New Member
                  • Sep 2010
                  • 66

                  #9
                  Thanks alot for your time Kovik

                  Comment

                  • kovik
                    Recognized Expert Top Contributor
                    • Jun 2007
                    • 1044

                    #10
                    No problem.

                    Comment

                    Working...