Everything works ok except when I pass the user id with the $id_user variable.
It only fails me with the inner join, giving me the following error,
Catchable fatal error: Object of class User could not be converted to string in
Crud User contains,
public function usuarioCurso($id_usuario){
var_dump($id_usuario);
$db = BaseDatos::conectar();
$listadoUsuario = [];
$consultar = $db->prepare(
"SELECT u.id_usuario, c.id_curso, m.id_mcurso FROM Usuario u
INNER JOIN mapeo_curso m ON u.id_usuario = m.id_usuario
INNER JOIN Curso c ON c.id_curso = m.id_curso
WHERE $id_usuario = u.id_usuario
");
$consultar->execute($id_usuario);
$consultar->fetchAll();
}
Profile tab,
$usuario = $crud->obtenerUsuario($_GET['id_usuario']);
$listado = $crud->usuarioCurso($usuario['id_usuario']);
If what you want is to filter by
id_usuario
the call the method should be done like this:Then the method must be modified:
$id_usuario
as a column name. The logical thing is that$id_usuario
it is the value to filter, in the query it must be represented with a placeholder?
or:nombre
if you wanted. And then, pass inexecute
the value that the method received in parameter.fetchAll
. That is, you tell it to do what it already did , given that precisely what it doesfetchAll
is return an array of the data set obtained.The corrected code would be more or less like this: