Currently keen on creating a powerful portal dedicated to astronautics. The project is at the final stage. Need a test script (test knowledge) of users. Or links to a lesson on creating tests, in general, I will be glad to any hint. An additional question: is the audience of programmers interested in Russian cosmonautics? February 4th.

I continue the topic. In search of a normal example of a test for knowledge testing, I found interesting implementation techniques. The test materials are here . Here is just one problem: how to properly handle the superglobal array coming in result.php, can anyone be able to solve the puzzle?

  • one
    eem ... maybe not everybody - oxyage 4:41 pm
  • or rather not at all practically all. - Artem
  • one
    At the time, I also searched, so I did not find anything worthwhile. I had to write my crutch (this is not as difficult as it may seem). - Drakmail pm
  • one
    I remember that @ cy6erGn0m was interested in nebulae :) Perhaps there is not only a drawing interest. I would have looked too. In any case, the link in the profile is not banned =) - Sh4dow

3 answers 3

Experts of the neighboring forum helped to solve the problem, thank you very much for that !!!

I post an example of the handler of the received arrays by the POST method:

<?php /* Обработка результатов тестирования */ // Переменные для подсчета правильных, частично правильных и неправильных ответов $right_answers = 0; $part_right_answers = 0; $wrong_answers = 0; // Массив с развернутыми сведениями $details = array(); // Внесение в массив данных из файла xml foreach($test->question as $q){ $qid = (int)$q[qid]; $qtype = (string)$q[type]; $text = (string)$q->text; $answer = (string)$q->answer; $details[$qid]['type'] = $qtype; $details[$qid]['text'] = $text; $details[$qid]['answer'] = $answer; if($qtype == 'checkbox' || $qtype == 'radio'){ foreach($q->choice as $c){ $caid = (int)$c[aid]; $details[$qid]['choices'][$caid] = (string)$c; } } } /* Прием ответов пользователя */ // Номер вопроса $qnum; // Прием ответов из $_POST foreach($_POST as $key => $answer){ if(substr($key, 0, 3) == 'qid'){ $qnum = (int)$answer; continue; } // Вносим ответ пользователя в массив с развернутыми данными if($details[$qnum]['type'] == 'checkbox'){ if(substr($key, 0, 3) == 'q'. $qnum . 'a'){ $details[$qnum]['useranswer'][] = $answer; } } else { $details[$qnum]['useranswer'] = $answer; } } /* Проверка правильности ответов */ foreach($details as $num => $det){ if((string) $det['answer'] === (string) $det['useranswer']){ // Если ответ совпадает: $score = 5; $right_answers += 1; } //Если ответ не совпадает else { // Если вопрос подразумевает множество ответов: if(is_array($det['useranswer'])){ // Перевод правильных ответов в массив $rightans = explode(',', $det['answer']); // Общее кол-во правильных ответов $rqt = count($rightans); // Общее кол-во ответов пользователя $uqt = count($det['useranswer']); // Сравнение ответов пользователя с правильными ответами foreach($det['useranswer'] as $ua){ if(in_array($ua, $rightans)){ $a += 1; } else { $b += 1; } } if($b > 0) { // Если есть неправильные ответы: // Кол-во ответов всего $allqt = count($det['choices']); // Отношение кол-ва прав.ответов пользователя ко всем правильным ответам $r = $a / $rqt; // Отношение кол-ва непр. ответов пользователя ко всем ответам $w = $b / $allqt; // Оценка $score = ($r - $w) * 5; if($score < 0) $score = 0; $part_right_answers += 1; } elseif($a < $rqt){ // Если кол-во правильных ответов меньше чем нужно: // Оценка $score = ($a / $rqt) * 5; $part_right_answers += 1; } else { // Оценка $score = 5; $right_answers += 1; } } else { // Если вопрос подразумевает один ответ: $score = 0; $wrong_answers += 1; } } // Вносим оценку в массив с развернутыми данными $details[$num]['score'] = $score; } // Количество вопросов в тесте $qcount = count($details); /* Вывод результатов тестирования */ ?> <ul> <li> Правильные ответы: <?php echo $right_answers; ?> (<?php echo ($right_answers / $qcount) * 100;?> %) </li> <li> Частично правильные ответы: <?php echo $part_right_answers; ?> (<?php echo ($part_right_answers / $qcount) * 100;?> %) </li> <li> Неправильные ответы: <?php echo $wrong_answers; ?> (<?php echo ($wrong_answers / $qcount) * 100;?> %) </li> </ul> <table> <tr> <th>№ В</th> <th>Вопрос</th> <th>Ваш ответ</th> <th>Правильный ответ</th> <th>Итог</th> </tr> <?php foreach ($details as $num => $row): ?> <tr> <td><?php echo $num; ?></td> <td><?php echo $row['text']; ?></td> <td> <?php if(is_array($row['useranswer'])){ echo implode(', ', $row['useranswer']); } else { echo $row['useranswer']; } ?> </td> <td><?php echo $row['answer']; ?></td> <td><?php echo $row['score']; ?></td> </tr> <?php endforeach; ?> 

    There are a lot of ready-made questionnaire scripts in the network.

    Scripts are searched for quiz, poll, test.

    • only they look useless. - NeonDT

    There is a script for creating and conducting tests that will be interesting for a novice programmer.

    • Built on the MVC paradigm
    • Data Caching (File | Apc | Eaccelerator | Memcache | Xcache)
    • Built-in template engine

    Feature List: http://mbcsoft.ru/products/eruditioncms.html

    Demo: http://etest.mbcsoft.ru/