By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

Adding Radio Buttons to my script. Need help.

P: 6
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
Jul 23 '07 #1
Share this Question
Share on Google+
1 Reply


kovik
Expert 100+
P: 1,044
This question sounds vaguely familiar. I believe I've answered it for you already at DevNetwork. That, or you just haven't gotten a chance to respond with further questions.
Jul 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.