Right I'm making an assessment and feedback system, which allows the instructor to create questions and the feedback for each answer given by the student. Now that works but what I'm having problems with is displaying the feedback for the students answer.
I'm using PHP version 4.3.2 with a MySQL backend. All data is stored in the MySQL database and pages created dynamically. Now the problem is that when the student selects the answer from "show_test.php", the page "show_feedback.php" is called, (code below) here the appropriate feedback is shown according to "testno" and "questionno" my problem is that I need to pass the "testno" and "questionno" from the previous page.
I am trying to do this using the PHP GET command and passing the variable in the URL. Now this would work fine if I knew what the values of "testno" and "questionno" were and could just write something like:
"action=show_feedback.php?testno=1&questionno=1"
However, as I do not know the values of "testno" and "questionno" I need to pass the variable instead of the data, so (in theory):
"action=show_feedback.php?testno=$testno&questionno=$questionno"
However, I know this won't work and was wondering if anyone could tell me the correct syntax or method to use here.
Regards,
Simon.
------------show_feedback.php------------------
Code: Select all
<?php
$answerno = $_POST['answer'];
$question = $_GET['questionno'];
$testno = $_GET['testno'];
#connect to database
$conn = @mysql_connect( "****", "****", "****" )
or die( "could not connect" );
#select the specified database
$rs = @mysql_select_db ( "db_sn202", $conn )
or die( "could not select database" );
#create the sql query
Switch($answerno)
{
Case '1' :
$sql="select feedback from question where testno = 'testno' and questionno = '$question'";
$rs = mysql_query( $sql, $conn )
or die( mysql_error() );
#write data
while( $row = mysql_fetch_array( $rs ) )
{
echo("" . $row["feedback"] );
}
break;
Case '2' :
$sql="select feedback2 from question where testno = '$testno' and questionno = '$question'";
$rs = mysql_query( $sql, $conn )
or die( mysql_error() );
#write data
while( $row = mysql_fetch_array( $rs ) )
{
echo("" . $row["feedback2"] );
}
break;
Case '3' :
$sql="select feedback3 from question where testno = '$testno' and questionno = '$question'";
$rs = mysql_query( $sql, $conn )
or die( mysql_error() );
#write data
while( $row = mysql_fetch_array( $rs ) )
{
echo("" . $row["feedback3"] );
}
break;
Case '4' :
$sql="select feedback4 from question where testno = '$testno' and questionno = '$question'";
$rs = mysql_query( $sql, $conn )
or die( mysql_error() );
#write data
while( $row = mysql_fetch_array( $rs ) )
{
echo("" . $row["feedback4"] );
}
break;
}
?>