I am making a nested query to the moodle database, because I am working with your data, the problem is that when making the nested query, it does not return anything, even the common result that the arrays return when there is nothing that is [], so I am a bit confused, I would like you to help me to understand my mistake.
the code is as follows:
the service.php is simply where I make the connection to the database using PDO, so I doubt that the error is from there
<?php
include("servicio.php");
$id= $_REQUEST["id"];
$res = $cnx->query("SELECT c.fullname, a.name, a.intro
FROM mdl_course AS c, mdl_assign AS a
WHERE c.id = a.course AND a.id IN(
SELECT s.assignment
FROM mdl_assign_submission AS s
WHERE a.id = s.assignment AND c.id IN(
SELECT l.courseid
FROM mdl_user_lastaccess AS l
WHERE l.courseid = c.id AND userid='$id'))");
if($res){
$datos = array();
foreach($res as $row){
$datos[]=$row;
}
echo json_encode($datos);
}
?>