Query looping problem- need help desperately

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

  • Query looping problem- need help desperately

    Hello everybody,

    I'm looking for somebody who can help me with my script.I'm trying to mix up all the snippets of mine and its messed up.This is a simple question and anwer script, to be more precisely a quiz script.

    First time, i show one question and when the user submit the answer, i would like to show the if the answer is right or wrong and then proceed to next question.THERE ARE ONLY 5 QUESTIONS.This is what i would like to do in my first phase.
    Right now, i'm able to show the question and when the user submits it, i'm also showing the answer but the other questions are also visible.I need to put in the loop my query but somewhere its missing.Could somebody please help me to fix my script and also i need to show the next button or link for the user to proceed to the next question.There are only 5 questions.
    you can see the working example HERE

    Thanks a million.

    PHP-Code:
    <?php


    include("contentdb.php");


    if (
    $id == "")
    {
    $id "0";
    }

    $display mysql_query("SELECT * FROM $table WHERE id > $id ORDER BY id ASC LIMIT 1 ",$db);

    if (!
    $submit) {

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

        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><td colspan=3><br><b>$question</b></td></tr>";
        echo 
    "<tr><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2 <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"></td></tr>";

        }

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

        echo 
    "</form>";

    }

    elseif (
    $submit

    {

    echo 
    "</p>";

    echo 
    "<p>Here are the answers:";

    echo 
    "<table border=0>";
    $display mysql_query("SELECT * FROM $table WHERE id > $id ORDER BY id ASC LIMIT 1",$db);
    while (
    $row mysql_fetch_array($display)) {

    $question $row["question"];
    $answer $row["answer"];
    $q $row["q"];

    echo 
    "<tr><td><br>$question</td></tr>";

    if ($
    $q == $answer
            {
            echo 
    "<tr><td>&raquo;you answered ${$q}, which is correct</td></tr>";
            }

    elseif ($
    $q == "") {
    echo 
    "<tr><td>&raquo;you didn't select an answer. The answer is $answer</td></tr>";
    }

    else {
    echo 
    "<tr><td>&raquo;you answered ${$q}. The answer is $answer</td></tr>";
    }

    }
    echo 
    "</table></p>";

    }

    ?>
    Zuletzt geändert von minds_gifts; 20.05.2003, 22:54.
    Happiness is a state of mind.
    Change your mind and be happy!

  • #2
    sorry for bad english.

    you must check which Q ist answered. is the answer correct , then put next Q.

    e.g.

    PHP-Code:
    if ($_POST["q1"]=="correct") {
       echo 
    "answer 1 is correct";

       if (
    $_POST["q2"]=="correct") {
          echo 
    "answer 1 is correct";
       }


    this you can repeat.

    always you need q1 , q2, q3 . this musst be saved temporary. or you works with session.

    hope this helps.
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Kommentar


    • #3
      Abraxax, you mis-understood me.Anyways, i fixed it to some extent.Now only one question is displayed and after submitting it, i'm displaying the answer for that.Fine, now i need to put up a link or a button for the next question.How can i do this???

      Please gimmi a snippet for this.

      Ps: you can check

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

      Kommentar


      • #4
        Original geschrieben von minds_gifts
        Please gimmi a snippet for this.
        ok. next ....

        file.php
        PHP-Code:
        switch($_GET["question"])
        {
           case 
        : if ($_POST["answer"])
                          {
                                
        // test answer => $ok = true;
                                
        if ($ok)
                                  
        header("Location: file.php?question=2");
                                else
                                   echo 
        "bad answer";
                          }
                         break;

            case 
        : ....

        INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


        Kommentar


        • #5
          Sorry Abraxax, I've gone dumb.I never used switch st's.I'm not very well experienced programmer and more over i really dont know where should i place your snippet in my code.I would be glad if somebody can place in the code of my first post.

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

          Kommentar


          • #6
            this forum can help but it is not doing for you.

            read the manual about switch
            http://de.php.net/manual/en/control-...res.switch.php

            and the manual
            http://de.php.net/manual/en/
            INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


            Kommentar


            • #7
              OK, to some extent i'm done but still things does'nt work in the way i want it to.

              well now, when i submit the answer for the first question, i get the answer and then proceed to second question, fine!when i submit the answer for the second question, surprisingly i get the answer of the FIRST question and when i click on the next question, i get the same second question displaying.Actually, it shld be the 3rd question.In total i've 5 questions.

              This piece of code is the one which executes when the answer is submitted:

              PHP-Code:
              if ($$q == $answer
                      {
                      echo 
              "<tr><td>&raquo;you answered ${$q}, which is correct</td></tr>";
                      
              $id $id+1
                      echo(
              "<a href=\"quizpage2.php?id=$id\">Next question</a>");
                      }

              elseif ($
              $q == ""
                      {
                      echo 
              "<tr><td>&raquo;you didn't select an answer. The answer is $answer</td></tr>";
                      
              $id $id+1
                      echo(
              "<a href=\"quizpage2.php?id=$id\">Next question</a>");

                      }

              else {
                  echo 
              "<tr><td>&raquo;you answered ${$q},which is wrong. The answer is $answer</td></tr>";
                      
              $id $id+1
                      echo(
              "<a href=\"quizpage2.php?id=$id\">Next question</a>");


              and before that i get the id field something like this
              PHP-Code:
              $id $HTTP_GET_VARS["id"]; 
              I feel that the id field continuity is missing, could somebody tell me where i'm going wrong.

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

              Kommentar


              • #8
                Original geschrieben von minds_gifts
                I feel that the id field continuity is missing, could somebody tell me where i'm going wrong.
                is it really missing, or are you just feeling like, "uh, i could be missing, but i don't really know..."?

                check this in the html output your php script is creating, is there the expected value for id concatenated to your links or not?
                I don't believe in rebirth. Actually, I never did in my whole lives.

                Kommentar

                Lädt...
                X