473,750 Members | 2,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Radio Buttons to my script. Need help.

6 New Member
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($textf ile));
fclose($file);
$delimiter = "\n";
$splitcontents = explode($delimi ter, $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($recor d));
fclose($file);
$delimiter = "\n";
$splitcontents = explode($delimi ter, $theData);
$expecting_answ er = 0;
$answer = "unknown";
$expecting_figu re = 0;
$figure = "unknown";
foreach( $splitcontents as $record )

{
if ($record == "QUESTION") {
// do something //
} else if ($record == "FIGURE") {
// do something //
$expecting_figu re = 1;
} else if ($expecting_fig ure) {
$figure = $record;
$expecting_figu re = 0;
} else if ($record == "OPTIONS") {
// do something else //
} else if ($record == "ANSWER") {
// do something else //
$expecting_answ er = 1;
} else if ($expecting_ans wer) {
$answer = $record;
$expecting_answ er = 0;
} else {

echo $record.'<br>';
}
}
}
?>

<html>
<body>
<?php
open_assignment ("./list.txt");

?>


Thank you for the help
Jul 23 '07 #1
1 1770
kovik
1,044 Recognized Expert Top Contributor
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
3504
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 ? <li>ABACAVIR SULFATE</li> <INPUT NAME="ingredient0" TYPE=checkbox VALUE="ABACAVIR SULFATE"><br> <input name="ABACAVIR SULFATE AMOUNT" type="radio" value="EQ 300MG BASE">EQ 300MG BASE<br> <input name="ABACAVIR SULFATE AMOUNT" type="radio" value="EQ...
10
13459
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 related to checkboxes. Thanks!!!
2
3493
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 "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I can't get to make this combo work. <p>Did you have any problems finding any of the information...
1
6891
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 grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
10
6103
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
5
3678
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 total number showen on screen, or on "submit" loop through the selected radio buttons and get the total. What I have at the moment will loop through all the buttons and just add all the totals, how do I get this code to add together the...
8
4613
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) that need to be validated when the submit button is clicked. Instead of the standard alert window popping up (which I have now), I want the radio button background color to change from the table color (E2E2E2) to red (FF0000) for both buttons...
3
2019
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 process()
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9583
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9342
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4888
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.