SQL to get participants

SQL to get participants

by Andrew P -
Number of replies: 2

Hello!

I am using a custom 'local' page to draw course grades. It works really well but I need a dropdown list to choose the student I want to view.

I found this code on these forums somewhere, and it works... but there are several students missing - maybe up to 10% - and I don't know what is wrong with the code. Any ideas?

I am open to get_enrolled_users as an alternative but I can't figure that out and can't find examples of it being used in a custom page.

Here is the code that results in a few missing - please help - thanks so much smile

Andrew

///////////////

$user_details_cat = $DB->get_records_sql("SELECT `u`.`firstname`, `u`.`lastname`, `u`.`email`, `u`.`id` FROM `mdlt2_role_assignments` AS `ra` JOIN `mdlt2_context` AS `context` ON `context`.`id` = `ra`.`contextid` AND `context`.`contextlevel` = 50 JOIN `mdlt2_course` AS `c` ON `c`.`id` = `context`.`instanceid` AND `c`.`id` = ".$currentCourse." JOIN `mdlt2_user` AS `u` ON `u`.`id` = `ra`.`userid`");


Average of ratings: -
In reply to Andrew P

Re: SQL to get participants

by Darko Miletić -

This should do it:

$courseid = 123; // Your course id number.
$users = get_enrolled_users(context_course::instance($courseid), 'moodle/grade:view', 0, 'u.*', 'u.lastname', 0, 0, true);
foreach ($users as $user) {
// Do stuff.
}