Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-18-2004, 09:01 PM   PM User | #1
gpopguru
New Coder

 
Join Date: Apr 2004
Location: PA
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
gpopguru is an unknown quantity at this point
Making a quiz... Need help coding

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:

Code:
<?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?
__________________
The Guru says:
Shiranu ga hotoke
Ignorance is bliss

My site >> www.mygpop.net
Home | My Blog | Forums | Art | Stories | Quizzes | What is G-POP? | Links

Last edited by gpopguru; 05-18-2004 at 09:33 PM..
gpopguru is offline   Reply With Quote
Old 05-18-2004, 09:32 PM   PM User | #2
gpopguru
New Coder

 
Join Date: Apr 2004
Location: PA
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
gpopguru is an unknown quantity at this point
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:

Code:
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.
__________________
The Guru says:
Shiranu ga hotoke
Ignorance is bliss

My site >> www.mygpop.net
Home | My Blog | Forums | Art | Stories | Quizzes | What is G-POP? | Links
gpopguru is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:46 AM.


Advertisement
Log in to turn off these ads.