Get all modules for a course in moodle

To create customised menu, we need to be able to run custom queries. Say I want to get all the modules for a course that I am enrolled, a query like this helps.

// say $course->id is the id of the course you want to look at

$sql = "select,, cm.instance from {modules} m, {course_modules} cm where and cm.course = '$course->id' and in (SELECT cs.sequence FROM {course_sections} cs where cs.course = '$course->id')";
$res = $DB->get_records_sql($sql);


I’ve created a simple relationship table. Hopefully, it helps.


Like it.? Share it:

Comments are closed.