Displaying a user's courses outside of Moodle via SQL query

Displaying a user's courses outside of Moodle via SQL query

by neptune 1 -
Number of replies: 0

Hi,

I'm using the following query to display a users courses on a PHP page.

Is there a way to return a hyperlink on the course fullname instead of plain text?

<?php

//Connection
include 'connection_file.php';   

//Query
$sql = "SELECT u.firstname, u.lastname, c.id, c.fullname\n"
. "FROM mdl_course AS c\n"
. "JOIN mdl_context AS ctx ON c.id = ctx.instanceid\n"
. "JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id\n"
. "JOIN mdl_user AS u ON u.id = ra.userid\n"
. "WHERE u.id = 4";

$result = $con->query($sql);

if ($result->num_rows > 0) {
    echo "<table><tr><th>First name</th><th>Last name</th><th>Course ID</th><th>Course</th></tr>";

 // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["firstname"]."</td><td>".$row["lastname"]."</td><td>".$row["id"]."</td><td>".$row["fullname"]."</td></tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}

$con->close();

?>

Thanks,
Chris

Average of ratings: -