LMSouq
moodle-core Open

Link directly to Moodle courses from PHP script

D-
D-T
1 month ago
3 views
Problem Description
Because of an excellent answer here in the forum, I was able to find out via sql which Moodle courses a certain Moodle user is enrolled in. I have now used this help in a PHP script, which also works extremely well. //Jetzt erfolgt die Überprüfung und Ausgabe, in welchen Kursen der Benutzer eingeschrieben ist. Die User-Identifikation erfolgt anhzand der user_id $sql = mysqli_query($db," SELECT DISTINCT CONCAT(u.firstname, ' ' ,u.lastname) AS Student, course.fullname AS Course FROM mdl_course AS course JOIN mdl_enrol AS en ON en.courseid = course.id JOIN mdl_user_enrolments AS ue ON ue.enrolid = en.id JOIN mdl_user AS u ON ue.userid = u.id WHERE u.id = '$user_id[$i]'" ); $sql_durchfuehren=mysqli_fetch_row($sql); //echo is_array($sql_durchfuehren) ? "Ja-Array" : "Nein kein Array"; if (is_array($sql_durchfuehren)) { echo "Der Benutzer ist in die folgenden Kurse eingeschrieben: <br>"; while($row = mysqli_fetch_array($sql)) { $course_name = $row['Course']; echo $course_name." <br>"; } } else { echo "<br>Der Benutzer ".$first_name[$i]." ".$last_name[$i]." ist in keinen Kurs eingeschrieben!<br>"; } With the script I now output the courses in which the respective user is enrolled. Challenge: Now I would like to directly link the courses in which the user is enrolled. So: User Tim Müller is enrolled in the Business English course. By clicking on "Business English" you should land directly in the course. How can I achieve this? Thanks and best regards You're great!!! D-T

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base