Page 1 of 1

Quiz in PHP

Posted: Sat Jul 06, 2002 3:49 pm
by Cornflake
I wanted to make a quiz for my website, and I came up with a way about doing it and I need you guy's help with the code.


[Idea]


Each question will have four multiple choice answers.

You choose your answer, A B C or D [A=1 B=2 C=3 D=4], and at the end of the page when you hit done, after taking the test, and your answers are added up and the total of your answer is printed


I hope the way I presented my information was in a professional manner in which someone can help me. Thanks in advance and any input would be appreciated.

Posted: Sat Jul 06, 2002 5:29 pm
by MacDaddy
how many questions?

Posted: Sat Jul 06, 2002 10:27 pm
by Cornflake
Probably about 25, but for the sake of learning it can be as many as you are willing to help me with. I want to you check boxes for the multi choice options...then depending on the one they choose they will get a number of points, then they will be added up when they click Done at the bottom of the page, then the next page will display the total points

Posted: Sat Jul 06, 2002 11:36 pm
by Cornflake
Here goes a code I developed thus far:

Code: Select all

<?
if($submit) &#123;
$score = $1+$2+$3;

if($score == 12) &#123;
$message = "You're a computer WHIZ!";
&#125; elseif($score >= 6) &#123;
$message = "Almost! Try harder!";
&#125; else &#123;
$message = "Study the web and try again later."; &#125;
echo $message; &#125; else &#123;
?>
<form action="<?=$PHP_SELF?>" method="post">
What is HTML used for?<br />
<input type="radio" name="1" value="1" />Getting high    
<input type="radio" name="1" value="2" />Losing weight    
<input type="radio" name="1" value="3" />Growing hair    
<input type="radio" name="1" value="4" />Making websites
<br /><br />

What is the current PHP version?<br />
<input type="radio" name="2" value="1" />4.1.0    
<input type="radio" name="2" value="2" />4.0.0    
<input type="radio" name="2" value="3" />1.0.0    
<input type="radio" name="2" value="4" />4.2.1
<br /><br />

What does CSS stand for?<br />
<input type="radio" name="3" value="1" />Caps Slinging Slaves    
<input type="radio" name="3" value="2" />Crackattics Sniffing Stuff    
<input type="radio" name="3" value="3" />Cows Seeing Supper    
<input type="radio" name="3" value="4" />Cascading Style Sheets
<br /><br />

<button type="submit" name="submit" value="  Get Score!  " />
</form>
<? &#125; ?>

Posted: Sun Jul 07, 2002 12:00 am
by untouchable
<?
$answerArray('A', 'B', 'C', 'D', 'D', 'B', 'C');
?>
....
<input type="radio" name="$question[0]" value='A'>
<input type="radio" name="$question[0]" value='B'>
<input type="radio" name="$question[0]" value='C'>
<input type="radio" name="$question[0]" value='D'>

...
for($c = 0; $c < $sizeOfYourAnswerArray; c++)
{
if($question[$c] == $answerArray[$c])
.........
}