Moodle培训师资料及其课程sql查询

时间:2015-05-26 06:58:05

标签: sql moodle

我想获得培训师及其课程清单:

我正在使用以下查询

SELECT u.id, u.firstname, u.lastname, u.email, c.fullname
FROM mdl_user u, mdl_role_assignments r, mdl_context cx, mdl_course c
WHERE u.id = r.userid
AND r.contextid = cx.id
AND cx.instanceid = c.id
AND r.roleid =3
AND cx.contextlevel =50

我只接受单一课程,需要帮助。

2 个答案:

答案 0 :(得分:1)

尝试以下

example.php?param1=region1&param2=&param3=

答案 1 :(得分:0)

如果您使用$ DB-> get_records_sql(),那么第一列必须是唯一的。因此,您需要结合用户ID和课程ID。

$sql = "SELECT CONCAT(c.id, '_', u.id) AS uniqueid,
                    u.id AS userid,
                    u.firstname,
                    u.lastname,
                    u.email,
                    c.id AS courseid,
                    c.fullname,
                    r.id
            FROM {user} u
            JOIN {role_assignments} ra ON ra.userid = u.id
            JOIN {role} r ON r.archetype = :archetype AND r.id = ra.roleid
            JOIN {context} cx ON cx.id = ra.contextid AND cx.contextlevel = :context
            JOIN {course} c ON c.id = cx.instanceid";
$params = array('context' => CONTEXT_COURSE, 'archetype' => 'teacher')
$trainers = $DB->get_records_sql($sql, $params);