Quiz in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cornflake
Forum Newbie
Posts: 3
Joined: Sat Jul 06, 2002 3:49 pm

Quiz in PHP

Post 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.
MacDaddy
Forum Newbie
Posts: 12
Joined: Sun May 05, 2002 9:36 pm
Location: Atlanta, GA

Post by MacDaddy »

how many questions?
Cornflake
Forum Newbie
Posts: 3
Joined: Sat Jul 06, 2002 3:49 pm

Post 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
Cornflake
Forum Newbie
Posts: 3
Joined: Sat Jul 06, 2002 3:49 pm

Post 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; ?>
User avatar
untouchable
Forum Newbie
Posts: 7
Joined: Sat Jul 06, 2002 11:41 pm

Post 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])
.........
}
Post Reply