...

View Full Version : Making a quiz... Need help coding



gpopguru
05-18-2004, 09:01 PM
I have my form all made up, I named all the radio buttons and everything (www.mygpop.net/test.php). Now the problem is the results. This is the code I have so far:



<?php
$water = 0;
$earth = 0;
$fire = 0;
$air = 0;
$night = 0;
$light = 0;
$i = 1;
$q = "q".$i;

for ($i=1; $i=10; $i++)
{

switch ($_POST[$q])
{
case 1:
$water = $water + 1;
break;
case 2:
$earth = $earth + 1;
break;
case 3:
$fire = $fire + 1;
break;
case 4:
$air = $air + 1;
break;
case 5:
$night = $night + 1;
break;
case 6:
$light = $light + 1;
break;
}
}

echo "water ".$water."<br />";
echo "earth ".$earth."<br />";
echo "fire ".$fire."<br />";
echo "air ".$air."<br />";
echo "night ".$night."<br />";
echo "light ".$light."<br />";
?>


I want it basically to go through every question (the names of the radio button groups are q1 to q10) and if the answer is a certain element, I want it to add to that element's count. The case numbers refer to the values I used in place of the element names on the form. I don't know what to do, I keep getting fatal errors saying that it exceeded 30 seconds. Can someone help me out a little?

gpopguru
05-18-2004, 09:32 PM
Ugh, I'm sorry. I shouldn't have posted when simple trial and error gets the job done. I changed the for loop to $i<=10 and I moved $q = "q".$i; into the loop. This fixed the problem... Here's the code from the part I changed:



for ($i=1; $i<=10; $i++)
{
$q = "q".$i;

switch ($_POST[$q])


Well, I guess my new question is if there's a better way to code that... I'm a php newbie, so inform me of any coding techniques I may have missed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum