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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    187
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Form that only shows 3 questions at a time

    I'm not sure if this is something that would be done with PHP or easier with CSS... I really have no clue. What I want to do is have a quiz with roughly 12 questions, but break it up into sections of 3. So a user would see three questions, select multiple choice (radio buttons) and then they could click "next" and the page would refresh to the next 3 questions and store the questions already answered... then at the end it would give the answers. What am I looking at to program something like this?

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yes PHP can do this. You could save the answers in a SESSION.

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Basically, you need to have a session variable which records which set of questions you are on, as well as a session variable to hold the answer to each problem. each time the user advances to the next page, you check to see which set of problems you are on, and show the correct ones.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #4
    Regular Coder
    Join Date
    Jan 2005
    Posts
    187
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I was hoping not to have to do "actual" multiple pages or sessions... what I was thinking of, was is it possible to have maybe 3-4 sets of questions within <div>'s and then show only 1 div at a time, then hide it after a users clicks a "next" link?

    So like <div> first 4 questions </div> NEXT ---> then it shows <div> second set of questions </div>.. then at the end a "submit" button to calculate everything?

  • #5
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Quote Originally Posted by a4udi View Post
    I was hoping not to have to do "actual" multiple pages or sessions... what I was thinking of, was is it possible to have maybe 3-4 sets of questions within <div>'s and then show only 1 div at a time, then hide it after a users clicks a "next" link?

    So like <div> first 4 questions </div> NEXT ---> then it shows <div> second set of questions </div>.. then at the end a "submit" button to calculate everything?
    That could really only be accomplished with PHP and Javascript - AKA AJAX. What you would do is make it so the Javascript would hide or unhide (style.display = "none";) depending on the answers or if certain fields were answered. You would then use AJAX to adjust either the $_SESSION variable or $_COOKIE using PHP.

    For more details on AJAX, check the Wikipedia page.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #6
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    PHP, Ajax and Jquery make it classic


  •  

    Posting Permissions

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