Databases: mdl_user and mdl_course enrollment

Databases: mdl_user and mdl_course enrollment

by Kelly Turner -
Number of replies: 2

Can anyone help me.  I have been playing with PYP trying to understand what data is in what tables and how they relate.  I have run into a problem. 

Our user are in the mdl_user table.  This table contains the mdl_user.id field. 

Our historical data is in the mdl_log.  I can query by mdl_log.userid (this is the same data as the mdl_user.id), The mdl_log also has the mdl_log.course field (this field shows the tbl_mdl_course.id field)  By creating a join between the mdl_log and the mdl_course tables I can view the course and individual viewed and the time they did it.

Here is my problem.  I need to built a query that will show me the individuals enrolled in a particular course.  I can't seem to find a record that would show the Student userid's enrolled in a particular course. 

Can anyone help me?

Average of ratings: -
In reply to Kelly Turner

Re: Databases: mdl_user and mdl_course enrollment

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This is a fairly frequently asked question, so a search should find you a detailed answer. The short and cryptic answer is you need mdl_role_assignments and mdl_context where contextlevel = 50.
In reply to Tim Hunt

Re: Databases: mdl_user and mdl_course enrollment

by Kelly Turner -

Thank you so much.  With this response and another one you posted in reply to SQL query to find currently enrolled students dated 12/6/2007, I was able to understand this relationship.

I'm attaching a layout image of an external database with table exported from PHP and how the relationships are working for me. 

Attachment Table_Relationship.gif