...

View Full Version : radio buttons in for statement



guido28
12-29-2006, 10:59 PM
Hi,

I'm building a quiz script and have run into two snags. I would appreciate any advise any of you can give me. I have gone through the php manual, by the way, but haven't found any answers.

Questions for the quizes are individual records in a db table. They can be in a multiple choice, fill in the blanks, modify statement or essay format. When someone opens the test a select query pulls the questions and, depending on the question type, creates a form field for each question using a for statement.

Everything is working cool except :

1) I am using radio buttons for the multiple choice and when I use answer[] as a name for the fields, they are grouped and only one radio button field (multiple choice question) can be selected from the quiz.
2) I haven't figured out how to add up the correct answers for a total score. There are functions that take the submitted answer and compare it to the correct answers and return "1" for correct and "0" for incorrect, but I haven't figured out a way to add all the 1's up.

Here's the main script:

<?php
session_start();

require('../../Settings.php');
require('TakeTestFunctions.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];
$AssignmentID = $_GET["AssignmentID"];
$MnMyUserID = $_GET["MnMyUserID"];
$Start = $_GET["Start"];
$Username = $_GET["Username"];
$Password = $_GET["Password"];
$MyResultID = $_GET["MyResultID"];
$Title = $_GET["Title"];
$warn = $_GET["warn"];

switch ($Section) {

Default:

$task = $_GET["task"];

if($task == 'insert') {

$answer = $_POST["answer"];
$line03 = $_POST["line03"];
$line01 = $_POST["line01"];
$line02 = $_POST["line02"];
$line05 = $_POST["line05"];
$AssignmentID = $_GET["AssignmentID"];
$UserID = $_GET["UserID"];
$RowCount = $_GET["RowCount"];

// insert results in database

for($x = 0; $x < sizeof($line01); $x++) {

$InsertAnswers = "INSERT INTO Aware_TestResults(Aware_TestResults_***, Aware_TestResults_UserID, Aware_TestResults_QID, Aware_TestResults_QT, Aware_TestResults_QA) VALUES('$line05[$x]', '$UserID', '$line03[$x]', '$line02[$x]', '$answer[$x]')";

$retid01 = mysql_db_query($db, $InsertAnswers, $conn);
}
// get results and score assignment

$GetResults = "SELECT * FROM Aware_TestResults WHERE Aware_TestResults_*** = '$AssignmentID' AND Aware_TestResults_UserID = '$UserID' AND Aware_TestResults_QT != 'QE' ";
$retid02 = mysql_db_query($db,$GetResults,$conn);

while ($row = mysql_fetch_array($retid02)) {
$line01b = $row["Aware_TestResults_ID"];
$line04b = $row["Aware_TestResults_QID"];
$line05b = $row["Aware_TestResults_QT"];
$line06b = $row["Aware_TestResults_QA"];

echo "<table>";

$a = array ($line01b);
foreach ($a as $value) {

echo "<tr>";

if($line05b == 'QC') {
$results = rmultiple($line04b,$line06b);
}elseif($line05b == 'QB') {
$results = rblanks($line04b,$line06b);
}elseif($line05b == 'QP') {
$results = rproof($line04b,$line06b);
}elseif($line05b == 'QE') {
$results = "0";
}

echo "<td>$line04b - $results</td>";

echo "<tr>";

} // end for each

echo "</table>";

} // end for while


}else{

echo "<table bgcolor=white cellspacing=5 cellpadding=5>";
echo " <tr>";
echo " <td>";
echo " <table bgcolor=white cellspacing=1 cellpadding=6>";

$GetAssignment = " SELECT Aware_TestConfig_ID, Aware_TestConfig_AssignmentID, Aware_TestConfig_Mode, LongName, Roster, teacher, keyavailable, baseurl, testtime, bhour, bday, bmonth, byear, ehour, eday, emonth, eyear, bhour1, bday1, bmonth1, byear1, filepath, ehour1, eday1, emonth1, eyear1, filelocation, randommethod, gradingmethod, announcement, cginame, trys, display, warn FROM Aware_TestConfig WHERE Aware_TestConfig_AssignmentID = '$AssignmentID' ";
$retid = mysql_db_query($db, $GetAssignment, $conn);

if (!$retid) { echo( mysql_error()); }
else {

while ($row = mysql_fetch_array($retid)) {
$Aware_TestConfig_ID = $row["Aware_TestConfig_ID"];
$Aware_TestConfig_AssignmentID = $row["Aware_TestConfig_AssignmentID"];
$Aware_TestConfig_Mode = $row["Aware_TestConfig_Mode"];
$LongName = $row["LongName"];
$Roster = $row["Roster"];
$teacher = $row["teacher"];
$keyavailable = $row["keyavailable"];
$baseurl = $row["baseurl"];
$testtime = $row["testtime"];
$bhour = $row["bhour"];
$bday = $row["bday"];
$bmonth = $row["bmonth"];
$byear = $row["byear"];
$ehour = $row["ehour"];
$eday = $row["eday"];
$emonth = $row["emonth"];
$eyear = $row["eyear"];
$bhour1 = $row["bhour1"];
$bday1 = $row["bday1"];
$bmonth1 = $row["bmonth1"];
$byear1 = $row["byear1"];
$filepath = $row["filepath"];
$ehour1 = $row["ehour1"];
$eday1 = $row["eday1"];
$emonth1 = $row["emonth1"];
$eyear1 = $row["eyear1"];
$filelocation = $row["filelocation"];
$randommethod = $row["randommethod"];
$gradingmethod = $row["gradingmethod"];
$announcement = $row["announcement"];
$cginame = $row["cginame"];
$trys = $row["trys"];
$display = $row["display"];
$warn = $row["warn"];

}
}
echo " <tr>";
echo " <td colspan=5><font face=verdana size=1>$announcement</font></td>";
echo " <tr>";

$GetQuestions = "SELECT * FROM Aware_TestRegQ WHERE Aware_TestRegQ_AssID = '$AssignmentID' ORDER BY Aware_TestRegQ_Order ";

$retid = mysql_db_query($db, $GetQuestions, $conn);

$RowCount = mysql_num_rows($retid);

if($RowCount == '0') {

echo "<tr><td valign=top colspan=100><font FACE=verdana size=2 valign=top>There are no questions in the test.</font></td></tr>";

} else {

echo "<form name=taketest method=post action=TakeTest.php?task=insert&AssignmentID=$AssignmentID&UserID=$MnMyUserID&RowCount=$RowCount>";

while ($row = mysql_fetch_array($retid)) {
$line01 = $row["Aware_TestRegQ_ID"];
$line02 = $row["Aware_TestRegQ_QT"];
$line03 = $row["Aware_TestRegQ_QID"];
$line04 = $row["Aware_TestRegQ_Order"];
$line05 = $row["Aware_TestRegQ_AssID"];

$a = array ($line01);
foreach ($a as $value) {

for($x = 0; $x < sizeof($line01); $x++) {
echo "<TR bgcolor=\"white\">\n";


if($line02 == 'QC') {
$questionform = qmultiple($line01,$line02,$line03,$line04,$line05);
}elseif($line02 == 'QB') {
$questionform = qblanks($line01,$line02,$line03,$line04,$line05);
}elseif($line02 == 'QP') {
$questionform = qproof($line01,$line02,$line03,$line04,$line05);
}elseif($line02 == 'QE') {
$questionform = qessay($line01,$line02,$line03,$line04,$line05);
}


echo "<input type=hidden name=line01[] value=$line01><input type=hidden name=line03[] value=$line03><input type=hidden name=line02[] value=$line02><input type=hidden name=line05[] value=$line05></tr>";
echo "<tr>";
echo "<td><hr size=\"1\" color=\"#CCCCCC\" noshade></td>";
echo "</tr>";
}
}
}
}
echo "<tr>";
echo "<td><input type=submit value=\"Submit Test\"></form></td>";
echo "</tr>";
echo " </table>";
echo " </td>";
echo " </tr>";
echo "</table>";

}

break;



} // end of switch

?>

guido28
12-29-2006, 11:01 PM
Here's the functions file:

<?php
session_start();

require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];




// function for logos

function qmultiple($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetMultiple = "SELECT * FROM Aware_TestMultA WHERE Aware_TestMultA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetMultiple,$conn);

while ($row = mysql_fetch_array($retid01)) {
$title = $row["Aware_TestMultA_Q"];
$ca = $row["Aware_TestMultA_CA"];
$d1 = $row["Aware_TestMultA_D1"];
$d2 = $row["Aware_TestMultA_D2"];
$d3 = $row["Aware_TestMultA_D3"];
$d4 = $row["Aware_TestMultA_D4"];
$clip = $row["Aware_TestMultA_Clip"];
$clipt = $row["Aware_TestMultA_ClipT"];
$img = $row["Aware_TestMultA_Img"];
$comment = $row["Aware_TestMultA_Comment"];
$*** = $row["Aware_TestMultA_***"];


echo "<td width=100%>";
echo "<table width=100%>";

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><b>$line04</b>. $title</font></TD>";
echo " </tr>";

if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "<tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

if(!$d4 and $d3 > 0) {
$answers = array($ca, $d1, $d2, $d3);
} elseif(!$d4 and !$d3) {
$answers = array($ca, $d1, $d2);
} else {
$answers = array($ca, $d1, $d2, $d3, $d4);
}

shuffle($answers);
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>";

foreach ($answers as $answers) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>";
echo " <input type=radio name=answer[] value=\"$answers\">&nbsp; $answers";
echo " </font></TD>";
echo " </tr>";
}



echo "</font></TD>";
echo " </tr>";


echo "<table>";
echo "</TD>";

}
}


function qblanks($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetBlank = "SELECT * FROM Aware_TestBlankA WHERE Aware_TestBlankA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetBlank,$conn);

while ($row = mysql_fetch_array($retid01)) {
$title = $row["Aware_TestBlankA_Q"];
$c1 = $row["Aware_TestBlankA_C1"];
$c2 = $row["Aware_TestBlankA_C2"];
$c3 = $row["Aware_TestBlankA_C3"];
$c4 = $row["Aware_TestBlankA_C4"];
$c5 = $row["Aware_TestBlankA_C5"];
$clip = $row["Aware_TestBlankA_Clip"];
$clipt = $row["Aware_TestBlankA_ClipT"];
$img = $row["Aware_TestBlankA_Img"];
$comment = $row["Aware_TestBlankA_Comment"];
$*** = $row["Aware_TestBlankA_***"];

echo "<td width=100%>";
echo "<table width=100%>";
if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

$input = "<input type=text name=answer[]>";
//$blank = "<input type=text name=$Q_$line01>";
//$string = '$title';
$patterns[0] = '/<_>/';
$name = preg_replace($patterns, $input, $title);

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><b>$line04</b>. $name</font> </TD>";
echo " </tr>";

echo "<table>";
echo "</TD>";

}
}

function qproof($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetProof = "SELECT * FROM Aware_TestProofA WHERE Aware_TestProofA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetProof,$conn);

while ($row = mysql_fetch_array($retid01)) {
$sentence = $row["Aware_TestProofA_S"];
$instructions = $row["Aware_TestProofA_I"];
$clip = $row["Aware_TestProofA_Clip"];
$clipt = $row["Aware_TestProofA_ClipT"];
$img = $row["Aware_TestProofA_Img"];
$comment = $row["Aware_TestProofA_Comment"];
$*** = $row["Aware_TestProofA_***"];

echo "<td width=100%>";
echo "<table width=100%>";

echo "<tr>";
echo "<td valign=top><font face=verdana size=1><b>$line04</b>. $instructions</font></td>";
echo "</tr>";

if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><textarea name=answer[]>$sentence</textarea></TD>";
echo " </tr>";
echo "<table>";
echo "</TD>";


}
}

function qessay($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetEssay = "SELECT * FROM Aware_TestEssayA WHERE Aware_TestEssayA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetEssay,$conn);

while ($row = mysql_fetch_array($retid01)) {
$title = $row["Aware_TestEssayA_Q"];
$rows = $row["Aware_TestEssayA_Row"];
$cols = $row["Aware_TestEssayA_Col"];
$clip = $row["Aware_TestEssayA_Clip"];
$clipt = $row["Aware_TestEssayA_ClipT"];
$img = $row["Aware_TestEssayA_Img"];
$comment = $row["Aware_TestEssayA_Comment"];
$*** = $row["Aware_TestEssayA_***"];

echo "<td width=100%>";
echo "<table width=100%>";

echo "<tr>";
echo "<td valign=top><font face=verdana size=1><b>$line04</b>. $title</font></td>";
echo "</TR>";

if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><textarea name=answer[] rows=$rows cols=$cols></textarea></TD>";
echo " </tr>";

echo "<table>";
echo "</TD>";


}
}

// functions for scoring test

function rmultiple($line03,$answer) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetMultiple = "SELECT * FROM Aware_TestMultA WHERE Aware_TestMultA_ID = '$line03' AND Aware_TestMultA_CA = '$answer' ";
$retid01a = mysql_db_query($db,$GetMultiple,$conn);

$Return = mysql_num_rows($retid01a);

if($Return > '0') {
return 1;
}else{
return 0;
}

}


function rblanks($line03,$answer) {
require('../../Settings.php');

$GetBlankr = "SELECT * FROM Aware_TestBlankA WHERE Aware_TestBlankA_ID = '$line03' AND Aware_TestBlankA_C1 = '$answer' OR Aware_TestBlankA_C2 = '$answer' OR Aware_TestBlankA_C3 = '$answer' OR Aware_TestBlankA_C4 = '$answer' ";
$retid01b = mysql_db_query($db,$GetBlankr,$conn);

$Return = mysql_num_rows($retid01b);

if($Return > '0') {
return 1;
}else{
return 0;
}

}

function rproof($line03,$answer) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetProof = "SELECT * FROM Aware_TestProofA WHERE Aware_TestProofA_ID = '$line03' AND Aware_TestProofA_C1 = '$answer' OR Aware_TestProofA_C2 = '$answer' OR Aware_TestProofA_C3 = '$answer' OR Aware_TestProofA_C4 = '$answer' ";
$retid01c = mysql_db_query($db,$GetProof,$conn);

$Return = mysql_num_rows($retid01c);


if($Return > '0') {
return 1;
}else{
return 0;
}

}



?>

Tyree
12-30-2006, 03:34 AM
To make things easier on others:

Main script:


<?php
session_start();

require('../../Settings.php');
require('TakeTestFunctions.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];
$AssignmentID = $_GET["AssignmentID"];
$MnMyUserID = $_GET["MnMyUserID"];
$Start = $_GET["Start"];
$Username = $_GET["Username"];
$Password = $_GET["Password"];
$MyResultID = $_GET["MyResultID"];
$Title = $_GET["Title"];
$warn = $_GET["warn"];

switch ($Section) {

Default:

$task = $_GET["task"];

if($task == 'insert') {

$answer = $_POST["answer"];
$line03 = $_POST["line03"];
$line01 = $_POST["line01"];
$line02 = $_POST["line02"];
$line05 = $_POST["line05"];
$AssignmentID = $_GET["AssignmentID"];
$UserID = $_GET["UserID"];
$RowCount = $_GET["RowCount"];

// insert results in database

for($x = 0; $x < sizeof($line01); $x++) {

$InsertAnswers = "INSERT INTO Aware_TestResults(Aware_TestResults_***, Aware_TestResults_UserID, Aware_TestResults_QID, Aware_TestResults_QT, Aware_TestResults_QA) VALUES('$line05[$x]', '$UserID', '$line03[$x]', '$line02[$x]', '$answer[$x]')";

$retid01 = mysql_db_query($db, $InsertAnswers, $conn);
}
// get results and score assignment

$GetResults = "SELECT * FROM Aware_TestResults WHERE Aware_TestResults_*** = '$AssignmentID' AND Aware_TestResults_UserID = '$UserID' AND Aware_TestResults_QT != 'QE' ";
$retid02 = mysql_db_query($db,$GetResults,$conn);

while ($row = mysql_fetch_array($retid02)) {
$line01b = $row["Aware_TestResults_ID"];
$line04b = $row["Aware_TestResults_QID"];
$line05b = $row["Aware_TestResults_QT"];
$line06b = $row["Aware_TestResults_QA"];

echo "<table>";

$a = array ($line01b);
foreach ($a as $value) {

echo "<tr>";

if($line05b == 'QC') {
$results = rmultiple($line04b,$line06b);
}elseif($line05b == 'QB') {
$results = rblanks($line04b,$line06b);
}elseif($line05b == 'QP') {
$results = rproof($line04b,$line06b);
}elseif($line05b == 'QE') {
$results = "0";
}

echo "<td>$line04b - $results</td>";

echo "<tr>";

} // end for each

echo "</table>";

} // end for while


}else{

echo "<table bgcolor=white cellspacing=5 cellpadding=5>";
echo " <tr>";
echo " <td>";
echo " <table bgcolor=white cellspacing=1 cellpadding=6>";

$GetAssignment = " SELECT Aware_TestConfig_ID, Aware_TestConfig_AssignmentID, Aware_TestConfig_Mode, LongName, Roster, teacher, keyavailable, baseurl, testtime, bhour, bday, bmonth, byear, ehour, eday, emonth, eyear, bhour1, bday1, bmonth1, byear1, filepath, ehour1, eday1, emonth1, eyear1, filelocation, randommethod, gradingmethod, announcement, cginame, trys, display, warn FROM Aware_TestConfig WHERE Aware_TestConfig_AssignmentID = '$AssignmentID' ";
$retid = mysql_db_query($db, $GetAssignment, $conn);

if (!$retid) { echo( mysql_error()); }
else {

while ($row = mysql_fetch_array($retid)) {
$Aware_TestConfig_ID = $row["Aware_TestConfig_ID"];
$Aware_TestConfig_AssignmentID = $row["Aware_TestConfig_AssignmentID"];
$Aware_TestConfig_Mode = $row["Aware_TestConfig_Mode"];
$LongName = $row["LongName"];
$Roster = $row["Roster"];
$teacher = $row["teacher"];
$keyavailable = $row["keyavailable"];
$baseurl = $row["baseurl"];
$testtime = $row["testtime"];
$bhour = $row["bhour"];
$bday = $row["bday"];
$bmonth = $row["bmonth"];
$byear = $row["byear"];
$ehour = $row["ehour"];
$eday = $row["eday"];
$emonth = $row["emonth"];
$eyear = $row["eyear"];
$bhour1 = $row["bhour1"];
$bday1 = $row["bday1"];
$bmonth1 = $row["bmonth1"];
$byear1 = $row["byear1"];
$filepath = $row["filepath"];
$ehour1 = $row["ehour1"];
$eday1 = $row["eday1"];
$emonth1 = $row["emonth1"];
$eyear1 = $row["eyear1"];
$filelocation = $row["filelocation"];
$randommethod = $row["randommethod"];
$gradingmethod = $row["gradingmethod"];
$announcement = $row["announcement"];
$cginame = $row["cginame"];
$trys = $row["trys"];
$display = $row["display"];
$warn = $row["warn"];

}
}
echo " <tr>";
echo " <td colspan=5><font face=verdana size=1>$announcement</font></td>";
echo " <tr>";

$GetQuestions = "SELECT * FROM Aware_TestRegQ WHERE Aware_TestRegQ_AssID = '$AssignmentID' ORDER BY Aware_TestRegQ_Order ";

$retid = mysql_db_query($db, $GetQuestions, $conn);

$RowCount = mysql_num_rows($retid);

if($RowCount == '0') {

echo "<tr><td valign=top colspan=100><font FACE=verdana size=2 valign=top>There are no questions in the test.</font></td></tr>";

} else {

echo "<form name=taketest method=post action=TakeTest.php?task=insert&AssignmentID=$AssignmentID&UserID=$MnMyUserID&RowCount=$RowCount>";

while ($row = mysql_fetch_array($retid)) {
$line01 = $row["Aware_TestRegQ_ID"];
$line02 = $row["Aware_TestRegQ_QT"];
$line03 = $row["Aware_TestRegQ_QID"];
$line04 = $row["Aware_TestRegQ_Order"];
$line05 = $row["Aware_TestRegQ_AssID"];

$a = array ($line01);
foreach ($a as $value) {

for($x = 0; $x < sizeof($line01); $x++) {
echo "<TR bgcolor=\"white\">\n";


if($line02 == 'QC') {
$questionform = qmultiple($line01,$line02,$line03,$line04,$line05);
}elseif($line02 == 'QB') {
$questionform = qblanks($line01,$line02,$line03,$line04,$line05);
}elseif($line02 == 'QP') {
$questionform = qproof($line01,$line02,$line03,$line04,$line05);
}elseif($line02 == 'QE') {
$questionform = qessay($line01,$line02,$line03,$line04,$line05);
}


echo "<input type=hidden name=line01[] value=$line01><input type=hidden name=line03[] value=$line03><input type=hidden name=line02[] value=$line02><input type=hidden name=line05[] value=$line05></tr>";
echo "<tr>";
echo "<td><hr size=\"1\" color=\"#CCCCCC\" noshade></td>";
echo "</tr>";
}
}
}
}
echo "<tr>";
echo "<td><input type=submit value=\"Submit Test\"></form></td>";
echo "</tr>";
echo " </table>";
echo " </td>";
echo " </tr>";
echo "</table>";

}

break;



} // end of switch

?>

functions file:


<?php
session_start();

require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];




// function for logos

function qmultiple($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetMultiple = "SELECT * FROM Aware_TestMultA WHERE Aware_TestMultA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetMultiple,$conn);

while ($row = mysql_fetch_array($retid01)) {
$title = $row["Aware_TestMultA_Q"];
$ca = $row["Aware_TestMultA_CA"];
$d1 = $row["Aware_TestMultA_D1"];
$d2 = $row["Aware_TestMultA_D2"];
$d3 = $row["Aware_TestMultA_D3"];
$d4 = $row["Aware_TestMultA_D4"];
$clip = $row["Aware_TestMultA_Clip"];
$clipt = $row["Aware_TestMultA_ClipT"];
$img = $row["Aware_TestMultA_Img"];
$comment = $row["Aware_TestMultA_Comment"];
$*** = $row["Aware_TestMultA_***"];


echo "<td width=100%>";
echo "<table width=100%>";

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><b>$line04</b>. $title</font></TD>";
echo " </tr>";

if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "<tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

if(!$d4 and $d3 > 0) {
$answers = array($ca, $d1, $d2, $d3);
} elseif(!$d4 and !$d3) {
$answers = array($ca, $d1, $d2);
} else {
$answers = array($ca, $d1, $d2, $d3, $d4);
}

shuffle($answers);
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>";

foreach ($answers as $answers) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>";
echo " <input type=radio name=answer[] value=\"$answers\">&nbsp; $answers";
echo " </font></TD>";
echo " </tr>";
}



echo "</font></TD>";
echo " </tr>";


echo "<table>";
echo "</TD>";

}
}


function qblanks($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetBlank = "SELECT * FROM Aware_TestBlankA WHERE Aware_TestBlankA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetBlank,$conn);

while ($row = mysql_fetch_array($retid01)) {
$title = $row["Aware_TestBlankA_Q"];
$c1 = $row["Aware_TestBlankA_C1"];
$c2 = $row["Aware_TestBlankA_C2"];
$c3 = $row["Aware_TestBlankA_C3"];
$c4 = $row["Aware_TestBlankA_C4"];
$c5 = $row["Aware_TestBlankA_C5"];
$clip = $row["Aware_TestBlankA_Clip"];
$clipt = $row["Aware_TestBlankA_ClipT"];
$img = $row["Aware_TestBlankA_Img"];
$comment = $row["Aware_TestBlankA_Comment"];
$*** = $row["Aware_TestBlankA_***"];

echo "<td width=100%>";
echo "<table width=100%>";
if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

$input = "<input type=text name=answer[]>";
//$blank = "<input type=text name=$Q_$line01>";
//$string = '$title';
$patterns[0] = '/<_>/';
$name = preg_replace($patterns, $input, $title);

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><b>$line04</b>. $name</font> </TD>";
echo " </tr>";

echo "<table>";
echo "</TD>";

}
}

function qproof($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetProof = "SELECT * FROM Aware_TestProofA WHERE Aware_TestProofA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetProof,$conn);

while ($row = mysql_fetch_array($retid01)) {
$sentence = $row["Aware_TestProofA_S"];
$instructions = $row["Aware_TestProofA_I"];
$clip = $row["Aware_TestProofA_Clip"];
$clipt = $row["Aware_TestProofA_ClipT"];
$img = $row["Aware_TestProofA_Img"];
$comment = $row["Aware_TestProofA_Comment"];
$*** = $row["Aware_TestProofA_***"];

echo "<td width=100%>";
echo "<table width=100%>";

echo "<tr>";
echo "<td valign=top><font face=verdana size=1><b>$line04</b>. $instructions</font></td>";
echo "</tr>";

if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><textarea name=answer[]>$sentence</textarea></TD>";
echo " </tr>";
echo "<table>";
echo "</TD>";


}
}

function qessay($line01,$line02,$line03,$line04,$line05) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetEssay = "SELECT * FROM Aware_TestEssayA WHERE Aware_TestEssayA_ID = '$line03' ";
$retid01 = mysql_db_query($db,$GetEssay,$conn);

while ($row = mysql_fetch_array($retid01)) {
$title = $row["Aware_TestEssayA_Q"];
$rows = $row["Aware_TestEssayA_Row"];
$cols = $row["Aware_TestEssayA_Col"];
$clip = $row["Aware_TestEssayA_Clip"];
$clipt = $row["Aware_TestEssayA_ClipT"];
$img = $row["Aware_TestEssayA_Img"];
$comment = $row["Aware_TestEssayA_Comment"];
$*** = $row["Aware_TestEssayA_***"];

echo "<td width=100%>";
echo "<table width=100%>";

echo "<tr>";
echo "<td valign=top><font face=verdana size=1><b>$line04</b>. $title</font></td>";
echo "</TR>";

if($comment) {
echo " <tr>";
echo " <td valign=top><font face=verdana size=1>$comment</font></td>";
echo " </tr>";
}else{
}

if($img) {
echo " <tr>";
echo " <td valign=top><img src=$RootUrl/pubdocs/$img></td>";
echo " </tr>";
}else{
}

if($clip) {
if($cliptype == 'wvid') {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";

} else {
$ClipPlay = "";
echo " <tr>";
echo " <td valign=top>$ClipPlay</td>";
echo " </tr>";
}
}else{

}

echo " <tr>";
echo " <td valign=top><font face=verdana size=1><textarea name=answer[] rows=$rows cols=$cols></textarea></TD>";
echo " </tr>";

echo "<table>";
echo "</TD>";


}
}

// functions for scoring test

function rmultiple($line03,$answer) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetMultiple = "SELECT * FROM Aware_TestMultA WHERE Aware_TestMultA_ID = '$line03' AND Aware_TestMultA_CA = '$answer' ";
$retid01a = mysql_db_query($db,$GetMultiple,$conn);

$Return = mysql_num_rows($retid01a);

if($Return > '0') {
return 1;
}else{
return 0;
}

}


function rblanks($line03,$answer) {
require('../../Settings.php');

$GetBlankr = "SELECT * FROM Aware_TestBlankA WHERE Aware_TestBlankA_ID = '$line03' AND Aware_TestBlankA_C1 = '$answer' OR Aware_TestBlankA_C2 = '$answer' OR Aware_TestBlankA_C3 = '$answer' OR Aware_TestBlankA_C4 = '$answer' ";
$retid01b = mysql_db_query($db,$GetBlankr,$conn);

$Return = mysql_num_rows($retid01b);

if($Return > '0') {
return 1;
}else{
return 0;
}

}

function rproof($line03,$answer) {
require('../../Settings.php');

$GroupID = $_GET["GroupID"];
$RegType = $_GET["RegType"];
$UserID = $_COOKIE["UserID"];

$GetProof = "SELECT * FROM Aware_TestProofA WHERE Aware_TestProofA_ID = '$line03' AND Aware_TestProofA_C1 = '$answer' OR Aware_TestProofA_C2 = '$answer' OR Aware_TestProofA_C3 = '$answer' OR Aware_TestProofA_C4 = '$answer' ";
$retid01c = mysql_db_query($db,$GetProof,$conn);

$Return = mysql_num_rows($retid01c);


if($Return > '0') {
return 1;
}else{
return 0;
}

}



?>

meth
12-30-2006, 03:51 AM
Guido, most of us only have a few minutes to spare for each post chosen to submit a reply to. You can make it easier for us by posting the problematic code snippets, not the whole she-bang.

Having said that, here's a few ideas: radio button groups will not do for multiple choice, this is not what they were designed for. Use checkboxes instead. For scoring, instantiate a var $total_score = 0; then each time an answer returns as 1 from your function, post increment the score var with $total_score++;

Tyree
12-30-2006, 04:09 AM
I'd have to disagree about checkboxes being the better option for multiple choice questions. If you have 4 possible answers, A, B, C, and D. You don't want the user to select ALL of them...you just want them to be able to choose 1 of them. So, radio buttons are still the best choice.

xconspirisist
12-30-2006, 04:41 AM
I believe meth was refuring to when a user could select multipul choices for the answer opposed to selecting just a single answer for a question. checkboxes would be the correct way to accomplish this.

guido28:

1) Use indentation. It makes your code SO much easier to read.

2) Use [php] tags when posting code. That requirement is within the forum rules which you should have read through before you make a request for help.

guido28
12-30-2006, 06:17 AM
I apologize for not following protocol. I should have read the rules before posting.

I have found a solution to the naming of the radio buttons: I'm using the row id as answer[$line01] instead of just answer[]. The array is correct in the processing section, but for some reason the first value drops to the second in the for statement there. I'm working on that now.

Meth, thanks for the solution to the addition problem.

3000today
01-02-2007, 03:28 AM
>> I'm building a quiz script

You might save yourself time and headaches by using the following software tool that creates quiz scripts better than you could from scratch:

http://www.pcshareware.com/qzscript.htm

HTH,

3_Ohs



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum