Courses in moodle database

Courses in moodle database

by Atanas Atanasov -
Number of replies: 6
Hello everybody
Sorry for my English, but it is not very well.
Can anyone help me to find in which table in moodle 1.8+ are store the relationship between user and the course where the user is belong.
I need this because i want to check which user in which course belong directly with sql query.
Thanks
Average of ratings: -
In reply to Atanas Atanasov

Re: Courses in moodle database

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
mdl_role_assignments and mdl_context

Something like

SELECT
 *
FROM
 mdl_user u,
 mdl_role_assignments ra,
 mdl_context con,
 mdl_course c,
 mdl_role r
WHERE
 u.id = ra.userid AND
 ra.contextid = con.id AND
 con.level = 50 AND
 con.instanceid = c.id AND
 ra.roleid = r.id AND
 r.shortname = 'student'
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Courses in moodle database

by Nicolas Martignoni -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
I think it should be "con.contextlevel" instead of "con.level" on the 3rd line of the where clause.
In reply to Tim Hunt

Re: Courses in moodle database

by Atanas Atanasov -
I think that will help me, but i have one question what is store in mdl_context table. Because before i take the course which student belong from mdl_course_display, but when one student visit some course more than one times there was record more than one row with userid and courseid.
And I make new user and enroll him in some course. There is no record in table mdl_course_display untill the user visit that course.

In reply to Atanas Atanasov

Re: Courses in moodle database

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
To understand tese concepts, you need to read http://docs.moodle.org/en/Roles_and_capabilities
In reply to Tim Hunt

Re: Courses in moodle database

by Atanas Atanasov -
Sorry for asking again, but i can't understand how can write an sql query to take courses where some user belong to when I have his id.
I want to make somthing like this.
There is many teachers an every teacher have own course (may have more than one course). I can take his id, name, but i don't know how i can take only the course/courses that manage (course id, shortname, fullname).
There is and many student that belong to some courses. But I don't know how to take the course id, shortname, fullname of the courses that user belong when i heve his id.
The idea is when some student take test in external database is saved his result.
Then when some teacher log into my system, I take his id and when he go to view the results from tested students to view only the results ot students that belong to his course. To do that i have to know the course/courses managed by the teachers and the courses that students belong to.
Thanks
P.S.: I hope to understand what i am trying to tell you.
In reply to Tim Hunt

Re: Courses in moodle database

by nyamdavaa ayush -
hello everybody, i need help, i need some SQL query that takes teacher names and students names from one course.

Example

course name, teachers names , student names, startdate

Examplecourse, nyamdavaa, ayush jonh , mary, smith 03\01\2009

is there any body can help me