2 questions regarding a quiz script

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • 2 questions regarding a quiz script

    hello everybody,

    I'm making a quiz application and right now i'm displaying all the questions from the table.To make it more attractive, I would like to display only one question at a time and click next button for the other questions.
    Should i simpliy modify my sql st or anything else??
    How can i do this one??

    One more question:
    Is that a possible to put a time bar(something which we see in flash), like say if the user does'nt answer a question say 20 sec's, it has to skip to the next question.

    Many thanks


    PHP-Code:
    include("contentdb.php");

    $display mysql_query("SELECT * FROM $table ORDER BY id",$db);
        
    if (!
    $submit) {


        echo 
    "<form method=post action=$PHP_SELF>";
        echo 
    "<table border=2>";

        while (
    $row mysql_fetch_array($display)) {   

        
    $id $row["id"];
        
    $question $row["question"];
        
    $opt1 $row["opt1"];
        
    $opt2 $row["opt2"];
        
    $opt3 $row["opt3"];
        
    $answer $row["answer"];

        echo 
    "<tr>";
        echo 
    "<td rowspan=4 background=schumi.jpg></td>";
        echo 
    "<td><b>$question</b></td></tr>";
        echo 
    "<tr><td><input type=radio name=q$id value=\"$opt1\">$opt1</td></tr>";
        echo 
    "<tr><td><input type=radio name=q$id value=\"$opt2\">$opt2</td></tr>";
        echo 
    "<tr><td><input type=radio name=q$id value=\"$opt3\">$opt3</td></tr>";

        }

        echo 
    "</table>";
        echo 
    "<input type='submit' value='See how you did' name='submit'>";
        echo 
    "</form>";


    Happiness is a state of mind.
    Change your mind and be happy!

  • #2
    1: Yes. Run the query. Display record one. Display a link to the same page (eg quiz.php) but with a GET parameter: quiz.php?number=2. In quiz.php, say $display = mysql_query("SELECT * FROM $table WHERE id=number",$db);. Only question 2 is displayed now. And so on. You need to run a full query every time to see when there are no more questions left.

    2: This is JavaScript related. Its defitinitely possible; however if you have big prizes in your quiz, I'd recommend using a Flash-Based bar as Javascript based bars could be tampered with.

    Kommentar


    • #3
      Thanks dude!
      well, i did'nt get you regarding the display of one question at a time.
      Alright, i'll write my select query something like:

      $display = mysql_query("select * from $table where id=number", $db");

      Now, I need to get this number incrementing everytime until the last question is reached

      how exactly, i can get this number??where should i put this parameter in my script??

      Ok, I'm gonna shoot with one more question:
      from the code which i've shown you, you should be able to guess that i show a question and 3 option values to choose for an answer and also an image.So far, my table sturucture looks something likeid, question, option1, option2, option3, answer)Well, i wanna display this image randomly, say if i've a pool of 100 images and i would like to show one each time.Or in another way, say lemme add a column image and put the image over there such that the image is associated to this question alone.

      Any ideas for better feasibility???

      Thank you
      Happiness is a state of mind.
      Change your mind and be happy!

      Kommentar


      • #4
        OK. First time you open quiz.php, there is no parameter set, so we set the question number to 1:

        if (!$id) $id = 1;

        Then we display the question:

        $display = mysql_query("SELECT * FROM $table WHERE id = $id",$db);
        etc.pp.

        Then we show the links to previous/next question:

        $previousID = $id - 1;
        $next ID = $id +1;

        Now we check whether there is a previous question to link to.
        if so, we output a link.

        if ($previousID > 0)
        echo "<a href='quiz.php?id=$previousID>Previous</a>";

        Now we check whether there is a next question to link to.
        if so, we ... you know.
        NB this is a very simple method and there MUST NOT be gaps
        in the IDs' sequence! IDs must be like: 1, 2, 3, 4, 5, 6, 7...

        $check = mysql_query("SELECT * FROM $table WHERE id = $nextID",$db);
        if (mysql_num_rows($check) > 0)
        echo "<a href='quiz.php?id=$nextID>Next</a>";





        I didnt get question 2: Are the images not associated with the questions? If not, just load all the image names into an array and display a random entry.

        Kommentar

        Lädt...
        X