Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2004
    Location
    PA
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?
    Last edited by gpopguru; 05-18-2004 at 10:33 PM.
    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

  • #2
    New Coder
    Join Date
    Apr 2004
    Location
    PA
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •