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 6713191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:21:00+00:00 2026-05-26T08:21:00+00:00

Sorry I have had to submit this question again because I have had hardly

  • 0

Sorry I have had to submit this question again because I have had hardly any views as it is an old post. I am desperate though for this to be answered. Please help me.

I have an array which will fetch rows from the database. But what I want to do is to create a new empty row in the table where if $row[‘StudentAnswer’] equals $row[‘AnswerContent’] then new field (lets say its called $row[‘StudentAnswerWeight’]) = $row[‘Weight%’] else $row[‘StudentAnswerWeight’] = ‘0’.

For example: $row[‘Answercontent’] = Leeds (This is the correct answer for the question.) $row[‘StudentAnswer’] = Leeds (This is what the student has put for the answer.) The $row[‘weight%’] is the percentage of the mark for the correct answer. Lets say that the answer for the above example = 5% of the total marks. Now as the above example shows that the student’s answer has matched the correct answer it means that in the new field which I want to create (lets call it ($row[‘StudentAnswerWeight’]) to display the wieght% percentage of the answer which is 5%. If the studnet got the answer wrong by lets say the Student put in his/her answer ‘Manchester’. The studentanswerweight should = 0% as that the answer is wrong. I hope you now understand what I want to acheive.

Can’t we make a new $row[‘…’]($row[‘StudentAnswerWeight’ is what the new $row[‘…’] will be called) and use an if statement. If $row[‘AnswerContent’] = $row[‘StudentAnswer’] then $row[‘…’] = $row[‘Weight%’] else $row[‘…’] = ‘0’. I was thinking along those lines but I could not get it to work, I hope you guys can figure it out 🙂

Below is the array and the fields in the table in php code:

<table border='1'>
  <tr>
  <th>Session ID</th>
  <th>Question Number</th>
  <th>Question</th>
  <th>Correct Answer</th>
  <th>StudentAnswer</th>
  <th>Correct Answer Weight</th>
  <th>Student Answer Weight</th>
  <th>Student ID</th>
  </tr>
  <?php

    while ($row = mysql_fetch_array($result)) {
            echo "
  <tr>
  <td>{$row['SessionId']}</td>
  <td>{$row['QuestionNo']}</td>
  <td>{$row['QuestionContent']}</td>
  <td>{$row['AnswerContent']}</td>
  <td>{$row['StudentAnswer']} </td>
  <td>{$row['Weight%']}</td>
  <td>{$row['StudentAnswer'] = $row['AnswerContent']}</td> 
  <td>{$row['StudentId']}</td>
  </tr>";
    }
  ?>

Thank You

  • 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-26T08:21:01+00:00Added an answer on May 26, 2026 at 8:21 am

    Add this before echo:

    if ( $row['StudentAnswer'] == $row['AnswerContent'] ) {
      $row['StudentAnswerWeight'] = $row['Weight%'];
    } else {
      $row['StudentAnswerWeight'] = '0';
    }
    

    And get rid of this {$row['StudentAnswer'] = $row['AnswerContent']}.

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

Sidebar

Related Questions

I am sorry I have already asked this question on Superuser, but nobody answers
I have been searching forever. Sorry, I am pretty desperate at this point so
im sorry if this has already been covered, i have had a look but
Sorry if I repeat my question but I have still had no clues of
Sorry I had to rephrase my question, I have a list preference with some
Sorry, i had to put the same post again due to still no solution
Sorry I missed and deleted earlier question on accident again. I have a situation,
im sorry if this was posted already i have been looking to no avail..
Sorry for the basic question - I'm a .NET developer and don't have much
Sorry for a pretty specific question. I have a table (see bottom), and when

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.