What I am trying to create is basically a page with a bunch of multiple choice questions. Basically just like a test page. I am providing the code lower. All the questions that need to show as a part of the test are stored in a separate database. There is also a test file "list.txt" that has names of files from the database that I want to display. That way you don't have to manually choose the questions. All you need is to generate a text file with questions you want to display.
Script consist of two functions. First one accesses the text file, reads it and adds names of file to the link of the database. second function opens questions from that database. All questions that same simple structure:
QUESTION
BLAH BLAH BLAH BLAH BLAH BLAH BLAH
FIGURE
None
OPTIONS
1
10
100
30
40
ANSWER
D
Additional code in second function omits lines Question, Answer, ect
Now here is my problem. I need to add radio buttons to my multiple choice answers so that they show correctly with each question.
Please help me if you can.
Thanks
Here is the code
Code: (PHP)
<?php
function open_assignment($textfile) {
$file = fopen($textfile, 'r') or die ("Can't open file1");
$theData = fread($file, filesize($textfile));
fclose($file);
$delimiter = "\n";
$splitcontents = explode($delimiter, $theData);
foreach( $splitcontents as $question )
{
open_question("./database/".$question);
echo '<hr>';
}
}
function open_question($record) {
$file = fopen($record, 'r') or die("Can't open file2");
$theData = fread($file, filesize($record));
fclose($file);
$delimiter = "\n";
$splitcontents = explode($delimiter, $theData);
$expecting_answer = 0;
$answer = "unknown";
$expecting_figure = 0;
$figure = "unknown";
foreach( $splitcontents as $record )
{
if ($record == "QUESTION") {
// do something //
} else if ($record == "FIGURE") {
// do something //
$expecting_figure = 1;
} else if ($expecting_figure) {
$figure = $record;
$expecting_figure = 0;
} else if ($record == "OPTIONS") {
// do something else //
} else if ($record == "ANSWER") {
// do something else //
$expecting_answer = 1;
} else if ($expecting_answer) {
$answer = $record;
$expecting_answer = 0;
} else {
echo $record.'<br>';
}
}
}
?>
<html>
<body>
<?php
open_assignment("./list.txt");
?>
Thank you for the help