Databases: Query to find teacher of a particular course in db

Re: Databases: Query to find teacher of a particular course in db

by Vu Tuan Anh -
Number of replies: 1

In your question, you need a query to get teacher. There is a way help you get contact of course of a specific course and print as html code without using query as the following:

$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
require_once($CFG->libdir. '/coursecatlib.php');
$tmpCourse = new course_in_list($course);
var_dump($tmpCourse);
//Add teacher name
// display course contacts. See course_in_list::get_course_contacts()
if ($tmpCourse->has_course_contacts()) {
$html .= html_writer::start_tag('ul', array('class' => 'teachers'));
foreach ($tmpCourse->get_course_contacts() as $userid => $coursecontact) {
$name = $coursecontact['rolename'].': '.
html_writer::link(new moodle_url('/user/view.php',
array('id' => $userid, 'course' => SITEID)),
$coursecontact['username']);
$html .= html_writer::tag('li', $name);
}
$html .= html_writer::end_tag('ul'); // .teachers
}

In reply to Vu Tuan Anh

Re: Databases: Query to find teacher of a particular course in db

by eli chan -

Thank you for sharing, it works for me to export teacher name in excel.