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
Add this before
echo:And get rid of this
{$row['StudentAnswer'] = $row['AnswerContent']}.