473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Adding Radio Buttons to my script. Need help.

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
1 1742
kovik
1,044 Expert 1GB
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

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

Similar topics

1
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ?...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
5
by: alanb | last post by:
Hi, hope someone can help, I need to be able to keep a running total of radio buttons selected, as a user goes through a set of 16 questions, devided in to 4 catorgories, then on "submit" have the...
8
by: photoboy | last post by:
I have racked by brain long enough on this, so now I need the help of someone who knows what they are doing. Here is what I am trying to achieve: First, I have two radio buttons (both unchecked)...
3
by: norbit | last post by:
Hello, I’m new to learning JavaScript. I was trying out a simple script but I can’t seem to make it work: <HTML><HEAD><TITLE>Radio Buttons</TITLE> <SCRIPT language=JavaScript> function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.