Hi,
I have problem with student enrollment when i change id data type in mdl_course from int(10) to varchar(10). I can enroll the student but when student logging in their page, they can't see the course that they have enrolled
thanks!
Change id data type in mdl_course
Number of replies: 3Re: Change id data type in mdl_course
Not a good idea to do that. mdl_course.id must be an int... if you need to keep track if the course code from a student management system or similar, use the idnumber field.
Don't change any of the "id" fields in the Moodle tables. You'll see all sorts of problems if you do.
Don't change any of the "id" fields in the Moodle tables. You'll see all sorts of problems if you do.
Re: Change id data type in mdl_course
if i use idnumber, how should i recognize student and the subject that they enrolled in mdl_user_students?.
how this table(mdl_user_students) save userid(from mdl_user) and courseid(from mdl_course)?
how this table(mdl_user_students) save userid(from mdl_user) and courseid(from mdl_course)?
Re: Change id data type in mdl_course
Moodle will know what to do ;)
If you need to do it as part of your script, you will want to do some SQL JOINs.
Here's some examples. The basic JOIN yo uwant looks like:
SELECT
s.*,u.idnumber,c.idnumber
FROM mdl_user_students s
JOIN mdl_user u ON s.userid=u.id
JOIN mdl_course c ON c.id=s.course
LIMIT 10;
(I put the limit 10 just in case, you don't need it).
If you want to narrow it down to a particular user you add a where clause:
SELECT
s.*,u.idnumber,c.idnumber
FROM mdl_user_students s
JOIN mdl_user u ON s.userid=u.id
JOIN mdl_course c ON c.id=s.course
WHERE u.idnumber = '#######'
(Replace ##### with the student id)
If you want to narrow down on a per-course basis look for the course id (c.idnumber) rather than for the user id (u.idnumber):
SELECT
s.*,u.idnumber,c.idnumber
FROM mdl_user_students s
JOIN mdl_user u ON s.userid=u.id
JOIN mdl_course c ON c.id=s.course
WHERE c.idnumber = '#######'
If this sounds too comples, check out the many SQL primers on Google.
If you need to do it as part of your script, you will want to do some SQL JOINs.
Here's some examples. The basic JOIN yo uwant looks like:
SELECT
s.*,u.idnumber,c.idnumber
FROM mdl_user_students s
JOIN mdl_user u ON s.userid=u.id
JOIN mdl_course c ON c.id=s.course
LIMIT 10;
(I put the limit 10 just in case, you don't need it).
If you want to narrow it down to a particular user you add a where clause:
SELECT
s.*,u.idnumber,c.idnumber
FROM mdl_user_students s
JOIN mdl_user u ON s.userid=u.id
JOIN mdl_course c ON c.id=s.course
WHERE u.idnumber = '#######'
(Replace ##### with the student id)
If you want to narrow down on a per-course basis look for the course id (c.idnumber) rather than for the user id (u.idnumber):
SELECT
s.*,u.idnumber,c.idnumber
FROM mdl_user_students s
JOIN mdl_user u ON s.userid=u.id
JOIN mdl_course c ON c.id=s.course
WHERE c.idnumber = '#######'
If this sounds too comples, check out the many SQL primers on Google.