PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP-如何在数据库中保存用户测验响应?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_261_0@moodle1.9如何在数据库中保存用户尝试测验结果以及用户尝试任何测验时更新哪些表?

请指导我.

如果可能的话,请更新我,哪些功能用于将用户测验尝试的数据插入moodle1.9数据库中?

解决方法:

从try.PHP文件(Moodle 1.9.7)中:

$attempt = quiz_create_attempt($quiz, $attemptnumber);

然后:

if (!$attempt->id = insert_record('quiz_attempts', $attempt)) {
            error('Could not create new attempt');
        }

从locallib.PHP

/**
 * Creates an object to represent a new attempt at a quiz
 *
 * Creates an attempt object to represent an attempt at the quiz by the current
 * user starTing at the current time. The ->id field is not set. The object is
 * NOT written to the database.
 * @return object                The newly created attempt object.
 * @param object $quiz           The quiz to create an attempt for.
 * @param Integer $attemptnumber The sequence number for the attempt.
 */
function quiz_create_attempt($quiz, $attemptnumber) {
    global $USER, $CFG;

    if (!$attemptnumber > 1 or !$quiz->attemptonlast or !$attempt = get_record('quiz_attempts', 'quiz', $quiz->id, 'userid', $USER->id, 'attempt', $attemptnumber-1)) {
        // we are not building on last attempt so create a new attempt
        $attempt->quiz = $quiz->id;
        $attempt->userid = $USER->id;
        $attempt->preview = 0;
        if ($quiz->shufflequestions) {
            $attempt->layout = quiz_repaginate($quiz->questions, $quiz->questionsperpage, truE);
        } else {
            $attempt->layout = $quiz->questions;
        }
    }

    $timeNow = time();
    $attempt->attempt = $attemptnumber;
    $attempt->sumgrades = 0.0;
    $attempt->timestart = $timeNow;
    $attempt->timefinish = 0;
    $attempt->timemodified = $timeNow;
    $attempt->uniquEID = question_new_attempt_uniquEID();

    return $attempt;
}

请参代码获取主要详细信息.

大佬总结

以上是大佬教程为你收集整理的PHP-如何在数据库中保存用户测验响应?全部内容,希望文章能够帮你解决PHP-如何在数据库中保存用户测验响应?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: