I have an online exam based php script. Right now the situation is like this. We can create different levels in the php based software. Suppose I create Level 1 and Level 2. In each level I created 3 tests. eg. Test 1.1, 1.2, 1.3 and 2.1, 2.2, 2.3. Right now the candidate is able to take test only one by one, but I want them to take Test 1.1 under Level 1 and thus continuously he should be able to take Test 1.2 and 1.3.

What I meant was see, as soon as Test 1.1 finishes I want the candidate to take 1.2 and 1.3. How can I do that?

This is the working of the quiz code. (In the quiz, see Next Question is there and at last question Submit and See Result will come. Now again the quiz(test 1.1) should redirect to the next test. I will share results code next)

<?php
  if (!defined("_VALID_PHP"))
      die('Direct access to this location is not allowed.');
?> <?php if(!$user->userlevel == 1): print Filter::msgInfo(lang('ADMINONLY'), false); return; endif;?> <?php
if(isset($_SESSION['qn']) && isset($_SESSION['eid'])){

        $exam = Core::getRowById("exams", $_SESSION['eid']);
        if(strtotime($_SESSION['quizend']) - strtotime(date("H:i:s")) <= 0){
                redirect_to("account.php?do=result");
        }else{


                if(isset($_POST['doQuize'])){

                          $data = array(
                                'uid' => intval($_POST['uid']), 
                                'token' => $_SESSION['token'], 
                                'qid' => intval($_POST['qid']), 
                                'type' => intval($_POST['type']), 
                                'exam' => intval($_SESSION['eid']),
                                'description' => $_POST['description'],
                                'marks' => $_POST['marks']
                          );

                          $lastid = $db->insert("tquestions", $data);

                          $answer = $_POST['answer'];
                          $correct = $_POST['correct'];

                          if($_POST['type'] == 1 || $_POST['type'] == 3){
                                  if(!empty($_POST['marked'])):
                                        $marked = $_POST['marked'];     
                                          foreach($marked as $a => $b){
                                                $data = array(
                                                        'tquestion' => intval($lastid), 
                                                        'uid' => intval($_POST['uid']),
                                                        'answer' => $answer[$a],
                                                        'correct' => $correct[$a],
                                                        'marked' => $marked[$a]
                                                );
                                                $db->insert("tanswers", $data);
                                          }
                                  endif;
                          } else if ($_POST['type'] == 2){

                                        $marked = intval($_POST['marked']);

                                        if($correct[$marked] == 1){
                                                $cor = 1; $mar = 1;
                                        }else{
                                                $cor = 4; $mar = $marked;
                                        }


                                        $data = array(
                                                        'tquestion' => intval($lastid), 
                                                        'uid' => intval($_POST['uid']),
                                                        'answer' => $answer[$marked],
                                                        'correct' => $cor,
                                                        'marked' => $mar
                                        );
                                        $db->insert("tanswers", $data);

                          } else if ($_POST['type'] == 4){
                                        $data = array(
                                                        'tquestion' => intval($lastid), 
                                                        'uid' => intval($_POST['uid']),
                                                        'answer' => $_POST['answer'],
                                                        'correct' => $_POST['correct'],
                                                        'marked' => $_POST['marked']
                                        );
                                        $db->insert("tanswers", $data);
                          }
                }

                if($_SESSION['total'] >= 1){
                        $qrow = $user->loadQuestion($_SESSION['eid'],$_SESSION['qn']);

                        $_SESSION['total'] = $_SESSION['total'] - 1;
                        $_SESSION['qn'] = $_SESSION['qn'] + 1;

                        $remaining = (strtotime ($_SESSION['quizend']) - strtotime (date("H:i:s")));
                        $mremaining = $remaining * 1000;
                }else{
                        redirect_to("account.php?do=result");
                }
                ?> <div class="row xform greentip"> <section class="col col-9" style="margin-bottom: 0;"> <?php echo '<h1>Exam: ' . $exam->title . '</h1>'; ?> <?php echo '<h3>Duration: ' . $exam->duration . ' minutes</h3>'; ?> <?php echo '<h3>Marks: ' . $user->sumMarks($exam->id) . '</h3>'; ?> <?php echo '<h3>Total Question: ' . $user->totalQues($exam->id) . '</h3>'; ?> </section> <section class="col col-3" style="margin-bottom: 0;"> <div id="timer" style="float:right;"> <script type="application/javascript">
                                        var myCountdownTest = new Countdown({
                                                time: <?php echo $remaining; ?>, 
                                                width:200, 
                                                height:80, 
                                                rangeHi:"minute"
                                        });
                                        </script> <script>
                                        setTimeout(function() {
                                                document.location.href='account.php?do=result';
                                        }, <?php echo $mremaining; ?>);
                                        </script> </div> </section> </div> <div id="msgresult"></div> <form id="ques_form" class="xform" method="post"> <div class="row" id="ques_area"> <section class="col col-12"> <?php $description = $qrow->description; ?> <h2>Question-<?php echo $_SESSION['qn'] . " (" . $qrow->marks . "Marks )" ;?></h2> <h3><?php echo "$description";?></h3> <?php $arow = $user->loadAnswer($qrow->id);?> <input type="hidden" name="uid" value="<?php echo $user->uid;?>" /> <input type="hidden" name="qid" value="<?php echo $qrow->id;?>" /> <input type="hidden" name="type" value="<?php echo $qrow->type;?>" /> <input type="hidden" name="description" value="<?php echo $qrow->description;?>" /> <input type="hidden" name="marks" value="<?php echo $qrow->marks;?>" /> <input name="doQuize" type="hidden" value="1" /> <?php $k = 1; $l = 0; ?> <?php foreach ($arow as $answers):?> <?php if($qrow->type == 1){?> <label class="radio"> <input type='radio' name='marked[0]' value='1' /><i></i><?php echo $k; ?>) True</label> <label class="radio"> <input type='radio' name='marked[0]' value='0' /><i></i><?php echo $k+1; ?>) False</label> <input type="hidden" name="correct[]" value="<?php echo $answers->correct;?>" /> <input type="hidden" name="answer[]" value="<?php echo $answers->answer;?>" /> <?php } else if($qrow->type == 2){?> <label class="radio"> <input type='radio' name='marked' value='<?php echo $l; ?>' /><i></i><?php echo $k; ?>) <?php echo $answers->answer; ?></label> <input type="hidden" name="correct[<?php echo $l; ?>]" value="<?php echo $answers->correct;?>" /> <input type="hidden" name="answer[<?php echo $l; ?>]" value="<?php echo $answers->answer;?>" /> <?php } else if($qrow->type == 3){?> <label class="radio"> <input type='checkbox' name='marked[<?php echo $l; ?>]' value='1' /><i></i><?php echo $k; ?>) <?php echo $answers->answer; ?></label> <input type="hidden" name="correct[]" value="<?php echo $answers->correct;?>" /> <input type="hidden" name="answer[]" value="<?php echo $answers->answer;?>" /> <?php } else if($qrow->type == 4){?> <label class="input"> <input type="text" name="marked"> </label> <input type="hidden" name="correct" value="<?php echo $answers->answer;?>" /> <input type="hidden" name="answer" value="<?php echo $answers->answer;?>" /> <?php } ?> <?php $k++; $l++; ?> <?php endforeach;?> <?php unset($answers);?> </section> </div> <footer><?php if($_SESSION['total'] >= 1){ echo '<button class="button" name="dosubmit" type="submit">Next Question</button>';}else{ echo 'This is the last question. <button class="button" name="dosubmit" type="submit">Submit & See Result</button>';} ?></footer> </form> <?php
        }
}else{
        redirect_to("courses.php");
}
?>

Result page code (See right now, what I did is I put an option, Take your next exam by clicking here, option. But this just goes back to exams page, where the candidate see test 1.1, 1.2, 1.3. But they should be connected.)

<?php
  if (!defined("_VALID_PHP"))
      die('Direct access to this location is not allowed.');
?> <?php if(!$user->userlevel == 1): print Filter::msgInfo(lang('ADMINONLY'), false); return; endif;?> <?php $exam = Core::getRowById("exams", $_SESSION['eid']); ?> <?php 
$totalscore = 0;
$pass = $core->passing_score;
$tQuestions = $user->tQuestions($_SESSION['token'], $_SESSION['eid']);
foreach ($tQuestions as $ques):
        $totalans = $user->totalAnswers($ques->qid);
        $newscore = $user->tAnswers($ques->id, $totalans, $ques->marks);
        $totalscore = $totalscore + $newscore;
endforeach;
unset($ques);
?> <section class="widget"> <div class="result"> <h1>Thank You for taking the test</h1> <?php $pscore = round($totalscore / $_SESSION['fullmarks'] * 100 , 2); ?> <br><br><br><br> <p><a href="account.php?do=review" class=""></a> <a href="#" class=""></a></p><br><br> <a href="exams.php"
        class="button button-secondary">Take your next exam by clicking here</a></p><br><br> </div> </section> <?php
if($pscore >= 60)
{$remarks = 1;}
else{$remarks = 0;}

$totalans = $user->processResult($user->uid,$_SESSION['eid'],$_SESSION['token'],$_SESSION['fullmarks'],$_SESSION['duration'],$totalscore,$pscore,$remarks);
?>

Now, listen I'm sharing the code of exams page.

<?php
        define("_VALID_PHP", true); 
        require_once("init.php"); 
?> <?php include("header.php"); ?> <?php switch(Filter::$do): case "details": ?> <?php $examsinfo = Core::getRowById("exams", Filter::$id); ?> <div class="row"> <section class="xform"> <h1>Exam Name: <?php echo $examsinfo->title; ?></h1> <h2>Total Question: <?php echo $user->totalQues(Filter::$id); ?></h2> <h2>Duration: <?php echo $examsinfo->duration; ?></h2><br/> <p>Syllabus: <?php echo $examsinfo->syllabus; ?></p> <?php if ($user->logged_in): ?> <?php $trow = $user->checkTaken($user->uid,Filter::$id);?> <?php if ($trow){?> <?php $rrow = $user->getResult($user->uid,Filter::$id);?> <p class="greentip"><i class="icon-lightbulb icon-2x pull-left"></i>You have already taken this exam </p> <a href="account.php?do=start&id=<?php echo Filter::$id;?>" class=""></a> <?php } else { ?> <a href="account.php?do=start&id=<?php echo Filter::$id;?>" class="button">Take This Exam</a> <?php } ?> <?php endif; ?> </section> </div> <?php break; ?> <?php default: ?> <?php $projectrow = $content->getExams();?> <?php $ptype = $content->getProjectTypes();?> <?php 
if(isset($_GET['sort']) && !empty($_GET['sort'])){
$courseinfo = Core::getRowById("project_types", $_GET['sort']);
?> <div class="pagetip"> <h1>Course Name: <?php echo $courseinfo->title;?></h1> <p>Description: <?php echo $courseinfo->description;?></p><br> <?php if($courseinfo->fees <= 0){ ?> <h2>FREE</h2> <?php } else { ?> <h2>Fees: $<?php echo $courseinfo->fees;?> USD<?php if($courseinfo->recurring == 1){ echo '/' . $courseinfo->days . $courseinfo->period; } ?></h2> <?php } ?> <?php if ($user->logged_in){ ?> <?php $erow = $user->checkEnrol($user->uid,$courseinfo->id);?> <?php if ($erow){?> <p class="greentip"><i class="icon-lightbulb icon-2x pull-left"></i>You have already enrolled in this course. You can take any exams.</p> <?php } else { ?> <a href="account.php?do=enrolment&id=<?php echo $courseinfo->id;?>" class="button exam-enrol">Enrol Now</a> <?php } ?> <?php } ?> </div> <?php } else { ?> <div class="row heading-row"> <h1>Available Exams</h1> </div> <?php } ?> <section class="widget"> <div class="content2"> <div class="row"> <div class="ptop10"> <form class="xform" id="dForm" method="post" style="padding:0;padding-top:15px"> <section class="col col-8"> <select name="select" id="coursefilter"> <option value="">-- Select Course --</option> <?php if ($ptype):?> <?php foreach ($ptype as $prow):?> <option value="<?php echo $prow->id;?>"<?php if($prow->id == get('sort')) echo 'selected="selected"';?>><?php echo $prow->title;?></option> <?php endforeach;?> <?php unset($prow);?> <?php endif;?> </select> </section> <section class="col col-2"> <?php echo $pager->items_per_page();?> </section> <section class="col col-2"> <?php echo $pager->jump_menu();?> </section> </form> </div> </div> <?php if(!$projectrow):?> <?php echo Filter::msgInfo(lang('PROJ_NOPROJECT'),false);?> <?php else:?> <table class="myTable"> <thead> <tr> <th class="header">Exam Title</th> <th class="header">Course Title</th> <th class="header">Duration</th> <th class="header"><?php echo lang('ACTIONS');?></th> </tr> </thead> <?php foreach ($projectrow as $row):?> <tr> <td><?php echo $row->title;?></td> <td><a href="exams.php?sort=<?php echo $row->course;?>"><?php echo $row->ctitle;?></a></td> <td><?php echo $row->duration;?> (minutes)</td> <td> <a href="exams.php?do=details&id=<?php echo $row->id;?>" class="button" data-title="<?php echo 'Add Question to: '.$row->title;?>">Start Here</a> </tr> <?php endforeach;?> <?php unset($row);?> </table> <?php if($pager->display_pages()):?> <?php echo $pager->display_pages();?> <?php endif;?> <?php endif;?> </div> </section> <script type="text/javascript"> 
// <![CDATA[  
$(document).ready(function () {
    $('#coursefilter').change(function () {
                var res = $("#coursefilter option:selected").val();
                (res == "NA" ) ? window.location.href = 'exams.php' : window.location.href = 'exams.php?sort=' + res;
    })
});
// ]]> </script> <?php break;?> <?php endswitch;?> <?php include("footer.php");?>

Now, please help me make the test continous or branched. Please.

Recommended Answers

All 13 Replies

Member Avatar for diafol

Why have you not indented your code to make it legible?

I (as well as others) will be put off from contributing due to the mess at the end of the first snippet and the third snippet. I suggest that you re-post with correct indenting and line breaks.

I'm sorry. Please help me now.

1ST PIECE OF CODE

<?php
  if (!defined("_VALID_PHP"))
      die('Direct access to this location is not allowed.');
?>

<?php if(!$user->userlevel == 1): print Filter::msgInfo(lang('ADMINONLY'), false); return; endif;?>


<?php
if(isset($_SESSION['qn']) && isset($_SESSION['eid'])){

    $exam = Core::getRowById("exams", $_SESSION['eid']);
    if(strtotime($_SESSION['quizend']) - strtotime(date("H:i:s")) <= 0){
        redirect_to("account.php?do=result");
    }else{


        if(isset($_POST['doQuize'])){

              $data = array(
                'uid' => intval($_POST['uid']), 
                'token' => $_SESSION['token'], 
                'qid' => intval($_POST['qid']), 
                'type' => intval($_POST['type']), 
                'exam' => intval($_SESSION['eid']),
                'description' => $_POST['description'],
                'marks' => $_POST['marks']
              );

              $lastid = $db->insert("tquestions", $data);

              $answer = $_POST['answer'];
              $correct = $_POST['correct'];

              if($_POST['type'] == 1 || $_POST['type'] == 3){
                  if(!empty($_POST['marked'])):
                    $marked = $_POST['marked']; 
                      foreach($marked as $a => $b){
                        $data = array(
                            'tquestion' => intval($lastid), 
                            'uid' => intval($_POST['uid']),
                            'answer' => $answer[$a],
                            'correct' => $correct[$a],
                            'marked' => $marked[$a]
                        );
                        $db->insert("tanswers", $data);
                      }
                  endif;
              } else if ($_POST['type'] == 2){

                    $marked = intval($_POST['marked']);

                    if($correct[$marked] == 1){
                        $cor = 1; $mar = 1;
                    }else{
                        $cor = 4; $mar = $marked;
                    }


                    $data = array(
                            'tquestion' => intval($lastid), 
                            'uid' => intval($_POST['uid']),
                            'answer' => $answer[$marked],
                            'correct' => $cor,
                            'marked' => $mar
                    );
                    $db->insert("tanswers", $data);

              } else if ($_POST['type'] == 4){
                    $data = array(
                            'tquestion' => intval($lastid), 
                            'uid' => intval($_POST['uid']),
                            'answer' => $_POST['answer'],
                            'correct' => $_POST['correct'],
                            'marked' => $_POST['marked']
                    );
                    $db->insert("tanswers", $data);
              }
        }

        if($_SESSION['total'] >= 1){
            $qrow = $user->loadQuestion($_SESSION['eid'],$_SESSION['qn']);

            $_SESSION['total'] = $_SESSION['total'] - 1;
            $_SESSION['qn'] = $_SESSION['qn'] + 1;

            $remaining = (strtotime ($_SESSION['quizend']) - strtotime (date("H:i:s")));
            $mremaining = $remaining * 1000;
        }else{
            redirect_to("account.php?do=result");
        }
        ?>

        <div class="row xform greentip">
            <section class="col col-9" style="margin-bottom: 0;">
                <?php echo '<h1>Exam: ' . $exam->title . '</h1>'; ?>
                <?php echo '<h3>Duration: ' . $exam->duration . ' minutes</h3>'; ?>
                <?php echo '<h3>Marks: ' . $user->sumMarks($exam->id) . '</h3>'; ?>
                <?php echo '<h3>Total Question: ' . $user->totalQues($exam->id) . '</h3>'; ?>
            </section>
            <section class="col col-3" style="margin-bottom: 0;">
                <div id="timer" style="float:right;">
                    <script type="application/javascript">
                    var myCountdownTest = new Countdown({
                        time: <?php echo $remaining; ?>, 
                        width:200, 
                        height:80, 
                        rangeHi:"minute"
                    });
                    </script>
                    <script>
                    setTimeout(function() {
                        document.location.href='account.php?do=result';
                    }, <?php echo $mremaining; ?>);
                    </script>
                </div>
            </section>
        </div>
        <div id="msgresult"></div>
        <form id="ques_form" class="xform" method="post">
            <div class="row" id="ques_area">
                <section class="col col-12">
                    <?php $description = $qrow->description; ?>
                    <h2>Question-<?php echo $_SESSION['qn'] . " (" . $qrow->marks . "Marks )" ;?></h2>
                    <h3><?php echo "$description";?></h3>

                    <?php $arow = $user->loadAnswer($qrow->id);?>
                    <input type="hidden" name="uid" value="<?php echo $user->uid;?>" />
                    <input type="hidden" name="qid" value="<?php echo $qrow->id;?>" />
                    <input type="hidden" name="type" value="<?php echo $qrow->type;?>" />
                    <input type="hidden" name="description" value="<?php echo $qrow->description;?>" />
                    <input type="hidden" name="marks" value="<?php echo $qrow->marks;?>" />
                    <input name="doQuize" type="hidden" value="1" />

                    <?php $k = 1; $l = 0; ?>
                    <?php foreach ($arow as $answers):?>

                        <?php if($qrow->type == 1){?>
                            <label class="radio">
                            <input type='radio' name='marked[0]' value='1' /><i></i><?php echo $k; ?>) True</label>
                            <label class="radio">
                            <input type='radio' name='marked[0]' value='0' /><i></i><?php echo $k+1; ?>) False</label>
                            <input type="hidden" name="correct[]" value="<?php echo $answers->correct;?>" />
                            <input type="hidden" name="answer[]" value="<?php echo $answers->answer;?>" />
                        <?php } else if($qrow->type == 2){?>
                            <label class="radio">
                            <input type='radio' name='marked' value='<?php echo $l; ?>' /><i></i><?php echo $k; ?>) <?php echo $answers->answer; ?></label>
                            <input type="hidden" name="correct[<?php echo $l; ?>]" value="<?php echo $answers->correct;?>" />
                            <input type="hidden" name="answer[<?php echo $l; ?>]" value="<?php echo $answers->answer;?>" />
                        <?php } else if($qrow->type == 3){?>
                            <label class="radio">
                            <input type='checkbox' name='marked[<?php echo $l; ?>]' value='1' /><i></i><?php echo $k; ?>) <?php echo $answers->answer; ?></label>
                            <input type="hidden" name="correct[]" value="<?php echo $answers->correct;?>" />
                            <input type="hidden" name="answer[]" value="<?php echo $answers->answer;?>" />
                        <?php } else if($qrow->type == 4){?>
                            <label class="input">
                                <input type="text" name="marked">
                            </label>

                            <input type="hidden" name="correct" value="<?php echo $answers->answer;?>" />
                            <input type="hidden" name="answer" value="<?php echo $answers->answer;?>" />
                        <?php } ?>

                        <?php $k++; $l++; ?>
                    <?php endforeach;?>
                    <?php unset($answers);?>
                </section>
            </div>           
            <footer><?php if($_SESSION['total'] >= 1){ echo '<button class="button" name="dosubmit" type="submit">Next Question</button>';}else{ echo 'This is the last question. <button class="button" name="dosubmit" type="submit">Submit & See Result</button>';} ?></footer>



        </form>      
        <?php
    }
}else{
    redirect_to("courses.php");
}
?>

3RD PIECE OF CODE

<?php
    define("_VALID_PHP", true); 
    require_once("init.php"); 
?>
<?php include("header.php"); ?>
<?php switch(Filter::$do): case "details": ?>
<?php $examsinfo = Core::getRowById("exams", Filter::$id); ?>

<div class="row">
    <section class="xform">
        <h1>Exam Name: <?php echo $examsinfo->title; ?></h1>
        <h2>Total Question: <?php echo $user->totalQues(Filter::$id); ?></h2>
        <h2>Duration: <?php echo $examsinfo->duration; ?></h2><br/>
        <p>Syllabus: <?php echo $examsinfo->syllabus; ?></p>

        <?php if ($user->logged_in): ?>
        <?php $trow = $user->checkTaken($user->uid,Filter::$id);?>
        <?php if ($trow){?>
            <?php $rrow = $user->getResult($user->uid,Filter::$id);?>
            <p class="greentip"><i class="icon-lightbulb icon-2x pull-left"></i>You have already taken this exam </p>
            <a href="account.php?do=start&amp;id=<?php echo Filter::$id;?>" class=""></a>
        <?php } else { ?>
            <a href="account.php?do=start&amp;id=<?php echo Filter::$id;?>" class="button">Take This Exam</a>
        <?php } ?>
        <?php endif; ?>

    </section>
</div>



<?php break; ?>
<?php default: ?>
<?php $projectrow = $content->getExams();?>
<?php $ptype = $content->getProjectTypes();?>
<?php 
if(isset($_GET['sort']) && !empty($_GET['sort'])){
$courseinfo = Core::getRowById("project_types", $_GET['sort']);
?>
<div class="pagetip">
    <h1>Course Name: <?php echo $courseinfo->title;?></h1>
    <p>Description: <?php echo $courseinfo->description;?></p><br>

    <?php if($courseinfo->fees <= 0){ ?>
        <h2>FREE</h2>
    <?php } else { ?>
        <h2>Fees: $<?php echo $courseinfo->fees;?> USD<?php if($courseinfo->recurring == 1){ echo '/' . $courseinfo->days . $courseinfo->period; } ?></h2>
    <?php } ?>

    <?php if ($user->logged_in){ ?>


        <?php $erow = $user->checkEnrol($user->uid,$courseinfo->id);?>
        <?php if ($erow){?>
            <p class="greentip"><i class="icon-lightbulb icon-2x pull-left"></i>You have already enrolled in this course. You can take any exams.</p>
        <?php } else { ?>    
            <a href="account.php?do=enrolment&id=<?php echo $courseinfo->id;?>" class="button exam-enrol">Enrol Now</a>
        <?php } ?>           

    <?php } ?>

</div>
<?php } else { ?>
<div class="row heading-row">
    <h1>Available Exams</h1>
</div>
<?php } ?>

<section class="widget">
  <div class="content2">
    <div class="row">
      <div class="ptop10">
        <form class="xform" id="dForm" method="post" style="padding:0;padding-top:15px">
          <section class="col col-8">
            <select name="select" id="coursefilter">
              <option value="">-- Select Course --</option>
              <?php if ($ptype):?>
              <?php foreach ($ptype as $prow):?>
              <option value="<?php echo $prow->id;?>"<?php if($prow->id == get('sort')) echo 'selected="selected"';?>><?php echo $prow->title;?></option>
              <?php endforeach;?>
              <?php unset($prow);?>
              <?php endif;?>
            </select>
          </section>


          <section class="col col-2"> <?php echo $pager->items_per_page();?> </section>
          <section class="col col-2"> <?php echo $pager->jump_menu();?> </section>
        </form>
      </div>
    </div>
    <?php if(!$projectrow):?>
    <?php echo Filter::msgInfo(lang('PROJ_NOPROJECT'),false);?>
    <?php else:?>
    <table class="myTable">
      <thead>
        <tr>
          <th class="header">Exam Title</th>
          <th class="header">Course Title</th>
          <th class="header">Duration</th>
          <th class="header"><?php echo lang('ACTIONS');?></th>
        </tr>
      </thead>
      <?php foreach ($projectrow as $row):?>
      <tr>
        <td><?php echo $row->title;?></td>
        <td><a href="exams.php?sort=<?php echo $row->course;?>"><?php echo $row->ctitle;?></a></td>
        <td><?php echo $row->duration;?> (minutes)</td>
        <td>
          <a href="exams.php?do=details&amp;id=<?php echo $row->id;?>" class="button" data-title="<?php echo 'Add Question to: '.$row->title;?>">Start Here</a>
      </tr>
      <?php endforeach;?>
      <?php unset($row);?>
    </table>
    <?php if($pager->display_pages()):?>
    <?php echo $pager->display_pages();?>
    <?php endif;?>
    <?php endif;?>
  </div>
</section>

<script type="text/javascript"> 
// <![CDATA[  
$(document).ready(function () {
    $('#coursefilter').change(function () {
        var res = $("#coursefilter option:selected").val();
        (res == "NA" ) ? window.location.href = 'exams.php' : window.location.href = 'exams.php?sort=' + res;
    })
});
// ]]>
</script>
<?php break;?>
<?php endswitch;?>
<?php include("footer.php");?>
Member Avatar for diafol

This code is full of static calls and object methods to which we have no access / info about. Are you using a framework?

You're also using alternative syntax for loops and conditionals, while not incorrect, is a little confusing (IMO). For example:

<?php if($pager->display_pages()):?>
<?php echo $pager->display_pages();?>
<?php endif;?>
<?php endif;?>

There is no indentation and there are needless open and close tags. An alternative...

<?php
...
    if($pager->display_pages())
    {
        echo $pager->display_pages();
    }
}
?>

...seems to be easier to follow. 300 lines of mashed up markup and php and js is a bit much. Sorry, I know I asked you to reformat it. Anybody?

Hi,

I have copied the code directly from file manager,can I share a pdf file with you,so that you can solve it. Moreover, I think it is an easy task for anybody who knows mysql and php basics. Most part of the code is actually not required. I shared it because you get an idea. Only the connection between quiz.php --> result.php --》 exam.php is required I guess for branching.

(including the snippet you shared for indenting is not a required part. Only places like 'Start Test' and related stuff.)

The test part of code is only required. I will give you the idea. In results code, we might need to redirect it back to exams and chose the next test. Thats it.

Somebody please reply.

Member Avatar for diafol

Sorry, I am not prepared to wade through 330 lines of code or extract the relevant bits. However, I could give you some pointers on rumbling on to the next test.

If you have a table such as 'tests':

id | main_test | test_part

E.g.

1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
4 | 2 | 1
5 | 2 | 2

etc.

WHen you finish test main_test = 1 and test_part = 1 (test 1.1 in other words), you could query the DB to see if main_test (=1) and test_part + 1 (=2) exists, if it does, then go to test 1.2, do this until main_test =1 and test_part +1 does not exist.

That's just one way.

Honestly, you've developed a bad coding habit already. I am not trying to be negative here, but the way I see it, you will have a hard time correcting them. Also, I second the moderator's comments above in regards to your excessive used of static methods. The way I see it, you are not using a framework.

If your only reason to use static method and properties is due to the namespacing, then you must find a way of creating a general config page.

So instead of doing this

class Filter
{
    protected static $do;
    /* or */
    public static $do;

}

why not put $do in the bootstrap file or in the config file..

If you are using static to mimic a Framework, then frameworks uses static methods to serve immediate response to user's requests. However, there are underlying processes behind those static methods.

for example if you see

ParseController::getController();

On the view side, the above appears to be static. However, the getController() method can be returning an instantiated object + method setting a controller.

so, it can be something like this

class ParseController
{
    public $controller;

    public function __construct()
    {

    }

    public function setController()
    {
        return $this->controller;
    }

    public static function getController()
    {
        $object = new ParseController;

        return $object->setController();
    }


}

Things can be very tricky ...

See I need to solve this very urgently. Somebody please help via chat.

Member Avatar for diafol

See I need to solve this very urgently. Somebody please help via chat.

THe PHP sticky: https://www.daniweb.com/web-development/php/threads/435023/read-this-before-posting-a-question clearly states:

Do not tell us how urgent your problem is. Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.

You have not responded to earlier comments and you show no progress, so I'm assuming contributors are still waiting for you. You are the one holding things up, not us.

In addition you provide a link to another site where you have posted the same question. This really won't do. You will penalise sites for holding duplicate data - very bad in the eyes of search engines like Google. It also wastes our time, as you may be getting a solution from elsewhere, but we'd be unaware of it.

See, I never meant to ditch you. I just told try to help me. Im a student, I have a task ahead. Please Sir.

See dont analyse the full code above. I just need to do this.

In the last part of quiz.php, you'll see that there is a submit and see result button. I just need the code to check whether this is the last exam in the course. If yes show result. Otherwise, start next test.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.