i'm printing the contents of 2 tables to a page, using for loops. the output are questions and answers. each answer has a value assigned to it. i need to be able to calculate the mark of what the user has when he answers it. to do this i thought about working out the total number of questions, and multiplying it by 4( as 4 is the higjhest value asigned to a question), but the problem is i dont know how to calculate the number of question that have been echoed. any help would be greatly appreciated
i've posted the code that i use to loop throught the questions and answers
<?PHP
for($i = 1; $i <= $numofrows; $i++) {
$row = pg_fetch_array($result2); //get a row from our result set
echo "
<br/><p>Question ".$row['questionno'].": " .$row['question']."</p>
\n";
$query2 = "SELECT answers.answerno, answers.answer, answers.answervalue, answers.questionno, answers.quizref, answers.answerref
WHERE answers.questionno = ".$row['questionno']. " AND answers.quizref = ".$id;
$result3 = pg_query($query2) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows2 = pg_num_rows($result3);
for($j = 0; $j < $numofrows2; $j++) {
$row2 = pg_fetch_array($result3); //get a row from our result set
echo "
<p>Answer ".$row2['answerno']." : <input type=\"radio\" name=\"" . $row['questionno'] . "\" id=\"selection[]\" value=\"" . $row2['answervalue'] . "\" onclick=\"this.form.total.value=calculateTotal(this);\" >".$row2['answer']."</p>
\n";
}
}
?>
Thanks