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

  • SEARCH
  • Home
  • 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 7661399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:35:36+00:00 2026-05-31T13:35:36+00:00

Given this table in my database: |AnswerID|QuestionID|AnswerText| |21 |2 |User | |22 |2 |Admin

  • 0

Given this table in my database:

|AnswerID|QuestionID|AnswerText|
|21      |2         |User      |
|22      |2         |Admin     |
|23      |2         |Guest     |
|24      |2         |User2     |

I have created a quiz using PAGINATION to display individual question and its options on each of the page. Example code snippet is as shown below:

$questionID=0;
while ($list = mysql_fetch_assoc($result)) 
{
echo $list['QuestionID'] . ":" . $list['QuestionText'] . "<br/>";  
$questionID=$list['QuestionID'];
}
$optionsquery="SELECT AnswerText,AnswerID FROM Options Where QuestionID=".$questionID;
$optionsresult=mysql_query($optionsquery) or die ('Query failed:'. mysql_error());
while($row = mysql_fetch_array($optionsresult))
{
echo "<br>";
echo "<input type='radio' id='radio-" . $row["QuestionID"] . "-" 
      . $row["AnswerID"] . "' name='" . $row["QuestionID"] 
      . "' value='" . $row["AnswerID"] . "' /> 
      <label for='radio-" . $row["QuestionID"] . "-" . $row["AnswerID"] . "'>" 
      . $row["AnswerText"] ."</label><br/>";
      echo "<br>";
}

Here is my objective. Given this relationship AnswerID<->AnswerText,
I want to store the selected radio chosen by the user into my database table of the following format :

|StudentID|QuestionID(e.g: 1)|QuestionID(e.g: 2)|
|678D     |AnswerID(e.g: 11) |AnswerID(e.g: 22) | 
|681D     |AnswerID(e.g: 14) |AnswerID(e.g: 23) |

As shown in the above,I am not hard-coding the questions and options for each page,they are rather taken from my database of tables. All the codes are being written in only one single PHP file. I have googled (on PHP) but I am confused on how to go about achieving my objective. Any code(PHP) snippets will be helpful as I am at loss of ideas. Thanks in advance.

  • 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-05-31T13:35:36+00:00Added an answer on May 31, 2026 at 1:35 pm

    I would suggest you don’t store it in that way (ie one question per column) …. You would be better creating a table that linked student, question and answer :

    Student    question     answer 
    678D       1            11 
    678D       2            22  
    681D       1            14 
    681D       2            23
    

    This gives you better flexibility – you can increase the number of questions easily for example.

    To make processing a submitted form easier I would change the HTML output to this :

    echo "<input type='radio' id='question[" . $row["QuestionID"] . "]' name='question[" .
    $row["QuestionID"] ."]' value='" . $row["AnswerID"] . "' />";
    

    This would produce inputs as an array which would maan processing them when submitted like this :

    $questions = $_POST['question']; // this returns an array like questions[questionid]
    foreach ($questions as $qid => $aid) {
        $query = 'INSERT INTO answertable(student,question,answer) VALUES
                  ($sudentid,$qid,$aid)';
    }
    

    You would need to change the answertable to the name of the table you are using to record answers. And $student would be obtained from the current session (im guessing thats where you are storing it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If i have this table on dataBase.js file: client.query( 'CREATE TEMPORARY TABLE IF NOT
We have a program in which each user is given their own Access database.
i have created table using Sqlite3.and also inserted record in that table.its running successfully.but
I have two tables in my database that look like this CREATE TABLE IF
I have a MySQL database table with this structure: table id INT NOT NULL
In SQLite, given this database schema CREATE TABLE observations ( src TEXT, dest TEXT,
when i give this sql query in my msaccess database table called warehouse1 it
Please give me some examples of jump table usage. I have seen this example
I have a table that has the following columns: GRVLID GRID Timein Timeout This
I want to have a database table that keeps data with revision history (like

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.