Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    4
    Member #
    15781
    I want to create a web quiz. each question will add or subtract from one of 9 values, and after submission, will print out numerical results.
    For example:
    Question 1:
    answer A = opt1+1,opt2+3,op4-2
    answer B =opt1-1,opt2+1,op3+2

    Output:
    opt1 total:
    opt2 total:
    opt3 total:
    opt4 total:

    Could this be done with just HTML? Is there a good tutorial somewhere I can learn about this particular kind of coding?
    Thanks!

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    I would approach this by using PHP scripting.
    (That means your question page would need to have the extension of .php)

    I'm not quite understanding the concept of your questions, but I'm thinking
    they are like "calculating a person's length of life" ... sort of like, if you smoke,
    you lose 5 points, if you don't you gain 5 points ... etc.

    Start out by creating a text file. This will be your simple database that contains
    the question number, question, answers and options.

    1|Question One|opt1|opt2|opt3|opt4|opt5|opt6|opt7|opt8|op9

    so it might look like this:

    1|This is Question One|2|-1|4|-5|-1|1|3|-3|4
    2|Question Two|2|-1|4|-5|-1|1|3|-3|4
    3|Question Three|2|-1|4|-5|-1|1|3|-3|4
    4|Question Four|2|-1|4|-5|-1|1|3|-3|4

    Now, the PHP script could open that text file (test1.txt) and generate
    your webpage from those questions. When they answer them, another
    PHP script will then take in all of the answers and do the calculations.

    Give us an example page of what your questions look like.
    Or explain it better ... what is supposed to happen with each question.

    ... and are you experienced with PHP?

    EDIT:

    An example of what I mean by using PHP to generate the webpage, the questions,
    and handling all of the question answers. All done with PHP and simple text files.
    http://www.bulletinlicensecenter.com/vanity/


    EDIT again ... for those interested in CSS ...

    See the neat "vanity" class I made to display those license plates.
    A good example of how CSS can make hard things really simple.


    .


  4. #3
    Junior Member
    Join Date
    Sep 2007
    Posts
    4
    Member #
    15781
    I've done the 'intro to PHP' tutorial, showing me how to get PHP to print a line on a page, does that count? =D

    More specific, the questions will direct the quiz-taker to one of nice specific groups. Each answer will give more or less points to any of the 9 groups.

    for example, if you answer question #1 with answer A, you get 4 pt in grp1, 2 pts in grp2, and -1 pts in grp3
    The purpose is to divine which group the test taker fits best in...

    There may be an easier way to do this, but all the web quizes i've viewed the soure of have each answer only adding to one value (answer a gievs 0, answer b gives 5, answer c gives 10). I don't see how I could divide 9 groups into just one value..

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    OK ...

    I would start by creating a text file that looks more like this ...
    Perhaps you call the text file something like, "test1.txt" ...

    1|Which group would you most likely fit into?
    1|A|3|-3|2|1|-4|5|1|-3|3
    1|B|3|-3|2|1|-4|5|1|-3|3
    1|C|3|-3|2|1|-4|5|1|-3|3
    1|D|3|-3|2|1|-4|5|1|-3|3

    2|What type of person do you think you are?
    2|A|3|-3|2|1|-4|5|1|-3|3
    2|B|3|-3|2|1|-4|5|1|-3|3
    2|C|3|-3|2|1|-4|5|1|-3|3
    2|D|3|-3|2|1|-4|5|1|-3|3


    Now, the PHP script, which is your web page, will open that text file and
    display all of the questions using the database. Once you determine how you
    will organize your database, we can come up with the PHP script.

    The PHP script will do all of the HTML creation for you and create the form also.

    When the user takes the test, it will call another PHP script to do all of the scoring.

    You only need to change the database to edit your test. That means, you will
    not have to create any other web pages and editing will be as easy as making
    changes to the text file and uploading the new file.

    That's the power of using PHP. Dynamically generated web pages.

    So, create a small text file with about 6 questions and show us what you have.
    Use the format I made, or come up with a format of your own.

    Each field in the textfile database is separated by a "pipe" | which is the backslash
    key shifted. This is typically what flatfile databases use to separate items.

    ==========

    To answer your other question about dividing one answer into nine groups ...

    Take my "test1.txt" file as an example ...

    Say that the PHP script creates the web page (and the form) and the user then
    looks at question 1. They answer "C" to that question (using a radio button).
    When the script scores the test, it knows that the user entered "C" for question "1".
    It then looks at the nine fields for "C" and does the math using those values.
    Notice there are 9 values for each answer "A", "B", "C", "D". All of those values
    will be different ... whatever you want.


  6. #5
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    This was a fairly easy script to create ...

    See this working example:
    http://www.catpin.com/radio.php


  7. #6
    Junior Member
    Join Date
    Sep 2007
    Posts
    4
    Member #
    15781
    Wow, thanks for posting that script!

    OK, I've compiled the following (don't laugh when you find out what my quiz is for, hah):

    class.txt
    1|Given a choice, I would rather:
    1|A|Run right into the thick of battle, and introduce my enemies to my weapons!|1|-2|-3|1|-3|3|2|-2|3
    1|B|Stay at the outskirts of a skirmish firing in, with large bursts of precision damage!|1|3|3|-1|1|-3|1|2|-3
    1|C|Wait, I have to fight things?|1|-2|-3|1|2|-3|1|-3|-3
    2|I'm having the most fun when:
    2|A|I am in The Zone, executing perfect combos and mastering the situation!|2|1|-1|-1|-2|3|1|1
    2|B|I am sitting back, and producing maximum results with little effort!|1|1|3|2|1|-2|1|1|-2
    2|C|Somewhere in between...|3|2|0|1|1|1|3|2|1
    3|My ideal character would be:
    3|A|The Jack of all Trades - I want to do everything!|4|-3|-3|2|-1|-3|4|-3|-1
    3|B|The Specialist - I can only do one thing, but damn, I do it really good!|-2|3|4|1|3|4|-2|2|1
    3|C|I'd like to be really good at one thing, but able to do OK in another area, as well...|1|-2|-3|2|3|-3|2|-2|3
    4|In a fight to the death, I would:
    4|A|Go all out, sacrificing defense for a massive offense!|-2|1|4|-3|1|4|1|3|-2
    4|B|Wait it out, tiring the opponent, letting him make the first mistake.|2|-2|-3|3|3|-3|2|-1|2
    4|C|I like to rough it up, but I like to live, too!|2|1|-2|2|1|0|3|1|2
    5|The best prey can be found:
    5|A|In the wilderness..|2|2|0|2|1|1|2|-1|3
    5|B|In the city ..|1|2|2|0|1|4|2|3|-2
    5|C|Hunting is Wrong!|1|1|-2|2|3|-4|-2|-1
    6|The best accomplishments are those that:
    6|A|Come as a team effort - working in harmony, we take down the world's biggest challenges!|1|-2|0|3|4|-1|2|4
    6|B|I accomplish on my own merit, the rest of you be damned!|2|4|2|-2|-2|2|1|2|-2
    6|C|I could see it either way...|2|1|1|-1|-1|-2|2|2|-1
    dr=1
    hn=2
    mg=3
    pl=4
    pr=5
    rg=6
    sh=7
    wl=8
    wr=9

    (the last bit there was just for my own reference)

    classchoice.php
    <html>
    <head>
    <title>What Class Should I Play in World of Warcraft?</title>
    </head>
    <body>
    Answer me these questions <i>six:</i>
    <form name="myform" action="results.php" method="POST">
    <div style="text-align:left; padding-left:30px;"><br>
    <?php
    $questions = file("./class.txt");
    $count=1;
    foreach ($questions as $question) {
    list($num, $ans, $question, $opt1,$opt2,$opt3,$opt4,$opt5,$opt6,$opt7,$opt8,$o pt9) = explode("|", $question);
    if($num == $count){
    if($opt1){
    echo "<input type='radio' name='test[$count]' value='$ans'> $question<br>\n";
    }
    else{
    echo "<b>$num</b> $ans<br />";
    }
    }#if num == count
    else{
    $count++;
    echo"<br />\n";
    }
    }#foreach
    ?>
    <br \>
    <input type="submit" name="submit" value="Submit">
    </div>
    </form>
    </body>
    </html>

    results.php
    <?php
    if (isset($_POST['submit'])) {
    $questions = file("./radio.txt");
    $count=1;
    $o1=0;
    $o2=0;
    $o3=0;
    $o4=0;
    $o5=0;
    $o6=0;
    $o7=0;
    $o8=0;
    $o9=0;
    foreach($_POST['test'] as $test_question) {
    //echo "$test_question \n";
    foreach ($questions as $question) {
    list($num, $ans, $question, $opt1,$opt2,$opt3,$opt4,$opt5,$opt6,$opt7,$opt8,$o pt9) = explode("|", $question);
    if(($num==$count)&&($test_question === $ans)){
    echo "<b>$num</b> $test_question --- $question<br />\n";
    $o1=$o1+$opt1;
    $o2=$o2+$opt2;
    $o3=$o3+$opt3;
    $o4=$o4+$opt4;
    $o5=$o5+$opt5;
    $o6=$o6+$opt6;
    $o7=$o7+$opt7;
    $o8=$o8+$opt8;
    $o9=$o9+$opt9;
    }
    else{
    //do nothing
    }
    }#foreach
    $count++;
    }#foreach
    echo"
    <br><br>
    Here's the results, the class with the highest number is best for you:<br>
    <b>Druid</b> $o1<br>
    <b>Hunter</b> $o2<br>
    <b>Mage</b> $o3<br>
    <b>Paladin</b> $o4<br>
    <b>Priest</b> $o5<br>
    <b>Rogue</b> $o6<br>
    <b>Shaman</b> $o7<br>
    <b>Warlock</b> $o8<br>
    <b>Warrior</b> $o9<br>
    ";
    }#isset submit
    ?>

    You can see the results at http://seriousstuff.org/classchoice.php
    Now, is there a way to rank the results by highest number? Or even print out the $opt with the highest number, then list the entire results sorted that way?

  8. #7
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    too funny.

    I can give you a solution, but maybe you want to try to figure it out yourself?

    Here's an idea ...

    Instead of creating separate variables, $o1, $o2, $o3 ...
    Make them an array instead ... $o[0], $o[1], $o[2] ...

    Then, use an array sort command to sort them.
    http://www.developertutorials.com/tu...114/page1.html

    note: sort() or rsort() ... for reverse sorting

    I'll let you play around with that, and if you really get stumped, let me (or us) know.

    I really want you to have the fun of learning PHP instead of using a script
    and not really understanding it ... after all, you'll want to expand more on it anyhow.


    EDIT:

    Upon trying to figure it out myself ...
    You'll want to use "associative reverse sort" or "arsort"
    See that in the tutorial.

    If you're stumped (and don't cheat now) ... see my new example:
    http://www.catpin.com/radio.php


    .


  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    This thread should really be moved to PHP .... maybe tomorrow I'll move over.


  10. #9
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Moved.

    You might want to consider an XML alternative... something like this:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <quiz>
        <question number="1" value="What is the answer?">
            <answer number="A" value="answer a" points="1" />
            <answer number="B" value="answer b" points="2" />
            <answer number="C" value="answer c" points="3" />
        </question>
    </quiz>

  11. #10
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    XML, especially with Flash:
    http://www.permadi.com/tutorial/flashMXQuiz/index.html

    But I think he might be interested in learning some PHP,
    so that's the direction we took. I've never done a quiz with
    XML, but that would be an interested thing to look at too.



Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:32 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com