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 to the CF scene
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    online quiz query

    I am at the first stage of creating a quiz.
    I wish to know is it possible to click a button to proceed to the next question, with questions to be asked using for/while loop

    I want to use

    1. php as scripting language.
    2. Mysql as database.
    3. For each correct answer there should be increment of 1 in score.
    4. all questions are multiple choice questions.

    I have writen a code but its not working properly,which is given below
    If u can suggest something it would be a great help

    Thanks in advance


    code which i have written is:-



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>

    <?php

    $host="localhost"; // Host name
    $username="root"; // Mysql username
    //$password=""; // Mysql password
    $db_name="rounds"; // Database name
    $tbl_name="round1"; // Table name

    // Connect to server and select databse.
    mysql_connect("$host", "$username")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql="SELECT id,question,a,b,c,d,ans FROM $tbl_name";
    $res=mysql_query($sql);
    $count=mysql_num_rows($res);
    //for($i=0;$i<$count;$i++)
    $i=0;
    $score=0;

    do{

    echo " ".mysql_result($res,$i,0);
    echo " ".mysql_result($res,$i,1).'<br/>';

    ?>
    <form method="get" >
    <p>
    <label>
    <input type="radio" name="RadioGroup1" value="<?php echo " ".mysql_result($res,$i,2);?>" />
    <?php echo " ".mysql_result($res,$i,2);?></label>
    <br>
    <label>
    <input type="radio" name="RadioGroup1" value="radio" />
    <?php echo " ".mysql_result($res,$i,3);?></label>
    <br>
    <label>
    <input type="radio" name="RadioGroup1" value="radio" />
    <?php echo " ".mysql_result($res,$i,4);?></label>
    <br>
    <label>
    <input type="radio" name="RadioGroup1" value="radio" />
    <?php echo " ".mysql_result($res,$i,5);?></label>
    <br>
    <?php
    if (isset($_POST['RadioGroup1'])) {
    $selected_radio = $_POST['RadioGroup1'];
    print $selected_radio;
    if($selected_radio==mysql_result($res,$i,6))
    {
    $score++;
    }
    }
    $i=$i+1;
    ?>
    </p>

    </form>
    <br>
    <?php
    }while($i<$count);
    ?>


    <form id="form1" name="form1" method="post" >
    <label>
    <input type="submit" name="Submit" value="Finish" />

    </label>
    <?php
    echo "$score";
    ?>
    </form>

    </body>
    </html>

  2. #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts

  3. Users who have thanked Fumigator for this post:

    swati soni (09-15-2009)


 

Posting Permissions

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