Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:15:53+00:00 2026-06-18T16:15:53+00:00

I have an application here: APPLICATION What I have is some questions and associated

  • 0

I have an application here: APPLICATION

What I have is some questions and associated with each questions in their possible answers in checkbox buttons, and three text inputs showing questionId, option type and number of marks for each individual answer.

Actually the number of marks for each individual answer if the problem I am getting. What I want to attempt is that for every correct answer for each question, they are associated with their own text input showing the number of marks they are worth (found in Individual_Answer Table below) else for all incorrect answers, they are all worth 0 in their text inputs/

Now here is the database tables for this example application:

Question:

QuestionId (PK auto)  QuestionNo  SessionId (FK Session) OptionId (FK Option)    
72                    1           26                     3
73                    2           26                     4

Option_Table:

OptionId (PK Auto)  OptionType
1                   A-C
2                   A-D
3                   A-E
4                   A-F

Answer:

AnswerId (PK auto)    QuestionId (FK Question)      Answer  
1                          72                         C             
2                          73                         A             
3                          73                         C             
4                          73                         D    

Individual_Answer:

AnswerId (PK auto)  AnswerMarks
1                   2
2                   2
3                   1
4                   2

The actual code is below:

//$qandaqry query is here and executed


        $qandaqrystmt->bind_result($qandaQuestionId,$qandaQuestionNo,$qandaQuestionContent,$qandaOptionType,$qandaAnswer,$qandaAnswerMarks );

        $arrQuestionId = array();
        $arrQuestionNo = array();
        $arrQuestionContent = array();
        $arrOptionType = array();
        $arrAnswer = array();
        $arrAnswerMarks = array();

        while ($qandaqrystmt->fetch()) {
        $arrQuestionId[ $qandaQuestionId ] = $qandaQuestionId; //QuestionId
        $arrQuestionNo[ $qandaQuestionId ] = $qandaQuestionNo; //QuestionNo
        $arrQuestionContent[ $qandaQuestionId ] = $qandaQuestionContent; //QuestionContent
        $arrOptionType[ $qandaQuestionId ] = $qandaOptionType; //OptionType
        $arrAnswer[ $qandaQuestionId ] = $qandaAnswer; //Answer
        $arrAnswerMarks[ $qandaQuestionId ] = $qandaAnswerMarks; //AnswerMarks
      }


    ?>
    <form action='results.php' method='post' id='exam'>

    <?php

//Retrieve options for each question

    function ExpandOptionType($option) { 
        $options = explode('-', $option);
        if(count($options) > 1) {
            $start = array_shift($options);
            $end = array_shift($options);
            do {
                $options[] = $start;
            }while(++$start <= $end);
         }
         else{
            $options = explode(' or ', $option);
         }
         echo '<p>';
         foreach($options as $indivOption) {
             echo '<div class="ck-button"><label class="fixedLabelCheckbox"><input type="checkbox" name="options[]" id="option-' . $indivOption . '" value="' . $indivOption . '" /><span>' . $indivOption . '</span></label></div>';
         }
          echo '</p>';


    }


    foreach ($arrQuestionId as $key=>$question) {

    ?>

    <div class="queWrap">

//Each QuestionNo and QuestionContent
    <p><?php echo htmlspecialchars($arrQuestionNo[$key]) . ": " .  htmlspecialchars($arrQuestionContent[$key]); ?></p>

//Output each Individual Option
    <p><?php echo ExpandOptionType(htmlspecialchars($arrOptionType[$key])); ?></p>

//Output each QuestionId text input per question
    <p>Question Id:<input type='text' class='questionIds' name='questionids' value='<?php echo htmlspecialchars($arrQuestionId[$key]); ?>' /></p>

//Output each OptionType text input per question
    <p>Option Type: <input type='text' class='optionType' name='optiontype' value='<?php echo htmlspecialchars($arrOptionType[$key]); ?>' /></p>

//Output each AnswerMarks per answer in each question
    <p>Each Answer's Marks<input type='text' class='answermarks' name='answerMarks' value='<?php echo htmlspecialchars($arrAnswerMarks[$key]); ?>' /></p>

    </div>


    <?php

    }

    ?>
    </form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:15:55+00:00Added an answer on June 18, 2026 at 4:15 pm

    First, I would like to recommend that you reconsider your DB schema. You have far more tables than you need to create a DB of questions, and all the joins etc. you need to retrieve a single question are expensive operations.

    Let’s say you want your HTML to look something like the following:

    <div class="queWrap" id="question-72">
        <h2 class="question-text">What is 4+4?</h2>
        <h3>Answers: <span class="questionMarks">(this question is worth 2 points)</span></h3>
    
        <div class="ck-button">
            <label class="fixedLabelCheckbox">
                <input type="checkbox" name="options_72[]" id="option-A" value="A">
                <span>0</span>
            </label>
        </div>
    
        <div class="ck-button">
            <label class="fixedLabelCheckbox">
                <input type="checkbox" name="options_72[]" id="option-B" value="B">
                <span>4</span>
            </label>
        </div>
    
        <div class="ck-button">
            <label class="fixedLabelCheckbox">
                <input type="checkbox" name="options_72[]" id="option-C" value="C">
                <span>8</span>
            </label>
        </div>
    
        <div class="ck-button">
            <label class="fixedLabelCheckbox">
                <input type="checkbox" name="options_72[]" id="option-D" value="D">
                <span>16</span>
            </label>
        </div>
    </div>
    

    Now let’s say your query’s result->fetch() above was rewritten more smartly like so:

    $_Questions = array();
    while( $qandaqrystmt->fetch() ) {
       $_Questions[] = array('id'=>$qandaQuestionId,'num'=>$qandaQuestionNo,'content'=>$qandaQuestionContent,'type'=>$qandaOptionType,'answer'=>$qandaAnswer,'marks'=>$qandaAnswerMarks);
    }
    

    Then to output the questions we just want to loop this and generate the appropriate HTML. I want to point out that it would be incredibly stupid to send the correct answer along with the question to the test taker, even if it is hidden within the html. You’ll note that this HTML is similar to your own, but has one alteration that is CRITICAL to make: because you only have ONE form element surrounding all of your questions, each question’s checkbox array needs a unique name. I’ve chosen to append _(questionID) to each array like so

    (e.g. question 72) <input type="checkbox" name="options_72[]" id="option-D" value="D">

    Here’s how you would loop it using a heredoc

    foreach( $_Questions AS $question ) {
      echo <<<EOT
        <div class="queWrap" id="question-{$question['id']}">
            <h2 class="question-text">{$question['content']}</h2>
            <h3>Answers: <span class="questionMarks">(this question is worth {$question['marks']} points)</span></h3>
        EOT;
    
    $options = ['A','B','C','D','E','F'];
    $lastOption = substr($question['type'], -1, 1);
    foreach( $options as $opt ) {
      echo <<<EOT
        <div class="ck-button">
            <label class="fixedLabelCheckbox">
                <input type="checkbox" name="options_{$questions['id']}[]" value="$opt">
                <span>$opt</span>
            </label>
        </div>
        EOT;
      if( $opt == $lastOption )
        break;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here is the problem: I have some logic in my application that will
I have some questions here and here the management of state in an ASP.NET
I have a Jsfiddle application here . If you type in a question in
here is a good question: I have an application compiled for iPhone OS 2.21.
Here is the scenerio: We have an application running on Webphere Portal Server 6.1
So here is the problem that I am facing: I have an application that
i have developed application for read information from card reader. Here i have used
I have an application I need to analyze. I have the source code here.
Kinda stuck here... I have an application with lets say 5000 rows of data
This is to create a greeting card application and here i have to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.