SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    where to put response?

    I've got the basic format working just fine. Just using tables for now may change later ok?
    When the user clicks on the button, I want to show to a repsonse at the bottom of the form.
    All text is shown in master division. So how and where do I do this?

    Eventually, I will have it so that the next question is not shown until the current question is answered.



    Code:
    $i=1;
    while($i<=10)  {  echo makeTable($ask);  $i++;  }
    
    function makeTable($ask)
    {
      global $i; $ask; $num;
    
    
    $num=$i;
    
    
    print "<div class='big'>
            <div class='qa'>".$ask[$i][1]."</div>
            <form name='question' action='' method='POST'>
            <table width='100%'>
              <tr>
                <td style='width:2em;'><input type='submit' name='pick' value='A'></td>
                <td class='yel'>".$ask[$i][2]."</td>
              </tr>
    
              <tr>
                <td style='width:2em;'><input type='submit' name='pick' value='B'></td>
                <td class='yel'>".$ask[$i][3]."</td>
              </tr>
    
              <tr>
                <td style='width:2em;'><input type='submit' name='pick' value='C'></td>
                <td class='yel'>".$ask[$i][4]."</td>
              </tr>
    
              <tr>
                <td style='width:2em;'><input type='submit' name='pick' value='D'></td>
                <td class='yel'>".$ask[$i][5]."</td>
              </tr>
    
            </table>
            </form>
    
          </div>";
    };

  2. #2
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You will need to use ajax or javascript to do this if I am understanding you... You want the user to click a button then upon that you want something like "correct, go to next question"?
    Ryan B | My Blog | Twitter

  3. #3
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your function will basically display all of the questions while on the loop, correct me if I'm wrong and I'm assuming the questions are stored in an array somewhere.

    Well as rguy84 suggested it looks like you need an Ajax solution for this or you can quit the loop and do something like a page redirection after each question is answered

    something like :

    question1.php will go to question2.php... etc ect. --> much easier to manage and develop

    cheers
    Don't Panic

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use session mechanism built in PHP.
    Because you want to keep answers, I believe

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.
    Changed the coding so the while loop no longer shows all the blocks at once.


    Code:
    print "<div class='big'>";
    $i=1;
     echo makeTable($ask,$i);
     print "<div class=chk>";
     echo $_POST['pick'];
     $answr=$_POST['pick'];
     if ($answr != $ask[$i][6] and $answr != "") echo " is wrong";
     print "<form name='mover' action='' method='post'>";
       print "<input type='submit' name='forward' value='previous'>";
       print "<input type='submit' name='forward' value='next'>";
     print "</form>";
     print "</div>";
    print "</div>";


Bookmarks

Posting Permissions

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