www.webdeveloper.com
Results 1 to 3 of 3

Thread: Mixing different types of question

  1. #1
    Join Date
    Jan 2014
    Posts
    4

    Mixing different types of question

    Please can some one help me to mix my quiz questions in this format: fill in the blank, true or false, multiple answers, matching and the rest. please all my questions are stored on the database. any time that I display my question they come in a radio button format.
    here is my code:

    <?php
    if (!isset($_SESSION)){
    session_start();
    }
    include("database.php");
    //include("counttime.php");
    extract($_POST);
    extract($_GET);
    extract($_SESSION);
    if(isset($subid) && isset($testid))
    {
    $_SESSION[sid]=$subid;
    $_SESSION[tid]=$testid;
    header("location:quiz.php");
    }
    if(!isset($_SESSION[sid]) || !isset($_SESSION[tid]))
    {
    header("location:index.php");
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Electronic Exams</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="quiz.css" rel="stylesheet" type="text/css">
    </head>

    <body>
    <?php
    include("header.php");
    include("counttime.php");

    //$sql = "SELECT * FROM se_question ORDER BY rand()";// LIMIT ()";
    $query="select * from se_question";
    $rs=mysql_query("select * from se_question where test_id=$tid",$cn) or die(mysql_error());

    //this below line displays the student picture as soon as the id is entered


    if(!isset($_SESSION[qn]))

    {
    $_SESSION[qn]=1; //fc
    mysql_query("delete from se_useranswer where sess_id='" . session_id() ."'") or die(mysql_error());
    $_SESSION[trueans]=1;//fc

    }
    else
    {
    if($submit=='Next Question' && isset($ans)) //this codes display the next question when click
    {
    mysql_data_seek($rs,$_SESSION[qn]);
    $row= mysql_fetch_row($rs);
    mysql_query("insert into se_useranswer(sess_id,test_id,que_des,ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."',$tid,'$row[2]','$row[3]','$row[4]','$row[5]','$row[6]','$row[7]','$ans')") or die(mysql_error());
    if($ans==$row[7])
    {
    $_SESSION[trueans]=$_SESSION[trueans]+1;
    }
    $_SESSION[qn]=$_SESSION[qn]+1;
    }
    else if($submit=='Get Result' && isset($ans))
    {
    mysql_data_seek($rs,$_SESSION[qn]);
    $row= mysql_fetch_row($rs);
    mysql_query("insert into se_useranswer(sess_id,test_id,que_des,ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."',$tid,'$row[2]','$row[3]','$row[4]','$row[5]','$row[6]','$row[7]','$ans')") or die(mysql_error());
    if($ans==$row[7])
    {
    $_SESSION[trueans]=$_SESSION[trueans]+1;
    }
    else{$_SESSION[trueans] =$_SESSION[trueans]+0;
    }
    echo "<h1 class=head1> Result</h1>";
    $_SESSION[qn]=$_SESSION[qn]+1;
    echo "<Table align=center><tr class=tot><td>Total Question<td> $_SESSION[qn]";
    echo "<tr class=tans><td>True Answer<td>".$_SESSION[trueans];
    $w=$_SESSION[qn]-$_SESSION[trueans];

    echo "<tr class=fans><td>Wrong Answer<td> ". $w;
    echo "</table>";
    mysql_query("insert into se_result(login, studentid, test_id,test_date,score) values('$login', '$studentid', $tid,'".date("Y/m/d")."',$_SESSION[trueans])") or die(mysql_error());
    echo "<h1 align=center><a href=review.php> Review Question</a> </h1>";
    unset($_SESSION[qn]);
    unset($_SESSION[sid]);
    unset($_SESSION[tid]);
    unset($_SESSION[trueans]);
    exit;
    }
    }

    $rs=mysql_query("select * from se_question where test_id=$tid",$cn) or die(mysql_error());
    if (!function_exists("GetSQLValueString"))

    //$sql = "SELECT * FROM se_question ORDER BY rand()";
    $rs=mysql_query("SELECT DISTINCT * FROM se_question WHERE que_desc IN (SELECT DISTINCT que_desc FROM se_question where test_id=$tid ) ORDER BY rand()",$cn) or die(mysql_error()); //fc
    if($_SESSION[qn]>mysql_num_rows($rs)-1)
    {
    unset($_SESSION[qn]);
    echo "<h1 class=head1>Please Error Occured</h1>";
    session_destroy();
    echo "Please <a href=index.php> Start Again</a>";

    exit;
    }
    mysql_data_seek($rs,$_SESSION[qn]);//fc
    $row= mysql_fetch_row($rs);
    //$quiz_shuffle = $_SESSION['se_question'];
    echo "<form name=myfm method=post action=quiz.php>";
    echo "<table width=100%> <tr> <td width=30>&nbsp;<td> <table border=0>";
    $n=$_SESSION[qn]+1;
    echo "<tr><td><span class=style2>Q ". $n .": $row[2]</style>"; //showing the question number plus the question
    echo "<tr><td class=style8><input type=radio name=ans value=1>$row[3]";
    echo "<tr><td class=style8><input type=radio name=ans value=2>$row[4]";
    echo "<tr><td class=style8><input type=radio name=ans value=3>$row[5]";
    echo "<tr><td class=style8><input type=radio name=ans value=4>$row[6]";
    function questionTypeNameParseObject($input) {
    // your code here.
    $this->setState(""); // Set the state if needed.
    return $output;
    }

    /*if($row[2]=1)
    {
    echo "<tr><td class=style8><input type=checkbox name=ans1 value=1 checked=checked>$row[3]";
    echo "<tr><td class=style8><input type=textarea name=ans2>";
    echo "<tr><td class=style8><input type=hidden name=ans3 value=3>";
    echo "<tr><td class=style8><input type=hidden name=ans4 value=4>";
    }*/
    if ($_SESSION[qn]+1)


    if($_SESSION[qn]<mysql_num_rows($rs)-1)

    echo "<tr><td><input type=submit name=submit value='Next Question'></form>";
    else
    echo "<tr><td><input type=submit name=submit value='Get Result'></form>";
    echo "<tr><td><input type=reset name=Reset value=Reset></form>";
    echo "</table></table>";
    ?>
    <a href="quiz_annex.php">section b</a>
    </body>
    </html>

  2. #2
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    The only time when your code has the option of changing how questions are presented is commented out and the if-statement is incorrectly written. It should be if($row[2] == 1) {...} assuming that each element in the $row array (retrieved from the MySQL database) will actually equal a number.

    To randomly present the questions in different formats, you could write a function that calculates a random number between a certain range. Using if-else statements or a switch, you can populate it with the question retrieved from your database.

    There are a few other concerns and problems with your code. First, what is the purpose of the function, questionTypeNameParseObject, which takes in a parameter that it doesn't use and outputs a variable that has no value. Second, mysql_ functions are going to be out of date, so you should use either mysqli or PDO functions to interact with your MySQL database.

  3. #3
    Join Date
    Jan 2014
    Posts
    4
    if can you post to me the switch or if statement that does that

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.15304 seconds
  • Memory Usage 2,874KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates