PHP Arrays and stuff

Status
Not open for further replies.

Toxic0n

Well-known member
1,109
I'm trying to develop an online quiz system using PHP/MySQL/Apache (big surpirse there).
One page can have up to 50 questions, each question has 4 radio buttons as answers, named like this:
a_1_1, a_1_2, a_1_3, a_1_4, a_2_1, etc, etc.
The question is, how do I pass all those answers into an array so I can easily compare the answers?
I want an array that looks like this
Code:
Answers[ 1 => 1, 2=>4, 3=>1....$i=>$a]
Where $i is the question number and $a is the correct answer.

This is how I'm going to compare them:
Code:
for($i=0; $i<$total; $i++)
	{	echo $i;
		$res = mysql_query("Select CorrectA, Qnum from Questions where Qnum = $i");
		$r = mysql_fetch_array($res);
		$correct= $r['CorrectA'];
		$Qnum = $r['Qnum'];
		$correct_answers[$Qnum]= $correct;
		
		
		if ($answers[$i]==$correct_answers[$i])
		{
			echo  "CORRECT";
		}
			
	
	
	}
Thanks
 

mattk

Ars Scholae Palatinae
807
What I meant was, instead of using your naming scheme, you can simply make each radio button part of an array, like:

<input type="radio" name="question[$questionID]" value="1">
<input type="radio" name="question[$questionID]" value="2">
<input type="radio" name="question[$questionID]" value="3">
<input type="radio" name="question[$questionID]" value="4">

for each question on the page. When it's passed to PHP it will already be an array, no parsing needed.
 

Clintology

Ars Legatus Legionis
15,566
Subscriptor
Originally posted by PerpetualNewbie:
email kilroy at elvis dot rowan dot edu

His Master's thesis was on an automated online quiz system, complete with student authentication.

He'll be of great help to you, I'm sure.

Feel free to say that Dan Paquette referred you.

Thats all it takes for a master's thesis these days? Two weeks of coding? :)

=clint
 
Status
Not open for further replies.