I have two related scripts. The first script displays a pass or fail icon depending on whether the value of passState is 1 or 0. If a student failed a quiz the row also displays a link to check.php so that the student can view their quiz attempt in a block of HTML named Result in the database. I need to create a session variable at this point to use as a local variable in check.php which is shown further down here. The problem I have is that the variable is being overwritten each row of the array, so that I can display Result for only the final row.
<?php
$query1 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' ORDER BY quizTitle ASC, passState DESC, userDate DESC ");
while ($row = mysql_fetch_array($query1))
{
$quizTitle = "{$row[quizTitle]}"; $_SESSION['quiztitle'][]=$quizTitle; echo "{$row['quizTitle']} <br />\n";
echo "{$row['userDate']} <br />\n";
if ("{$row['passState']}" == 1) {echo "<img src='good.png' /><br />\n";}
if ("{$row['passState']}" == 0) {echo "<img src='not_good.png' /><br />\n";}
if ("{$row['passState']}" == 0) {echo "<a href='check.php'>Check your answers.</a><br />\n";}
}
?>
Here's the relevant code for check.php.
<?php
session_start();
// Put session variables into local variables
// some other session variables converted to local variables
$quizTitle = $_SESSION['quizTitle'];
$sqlchk = "SELECT Result FROM quiz WHERE managerId = '$managerId' AND userIdRec = '$userIdRec' AND quizTitle = '$quizTitle'";
$rschk = mysql_query($sqlchk);
$rowchk = mysql_fetch_array($rschk, MYSQL_ASSOC);
echo (stripslashes($rowchk['Result']));}
?>
The code is good but the transfer of values in the variable is wrong as it always returns the Result for the final quizTitle in the array, but no others.
This code is obviously abbreviated to the necessary content.
I appreciate any help.