I have this method that I want to give me all usernames in the database, in a list.
I know that fetch() should be inside a look of some kind. But I don't know how to loop inside an object, because I've tried with a for and a while and I've got this error that says that it cannot be treated as an array or string (ie: Catchable fatal error: Object of class PDOStatement could not be converted to string).
So, How do I do a loop inside a result set?
The code below is my last attempt, and it shows only the first result (naturally, because it should be inside some kind of loop). I've looked into some other questions here, but as I'm just starting with objects, they are too complex and I cannot quite grasp the concept.
function getUsuarios() {
$usuariosRaw = $this->pdo->query('SELECT nombre FROM usuarios');
$listadoUsuarios = $usuariosRaw->fetch();
echo 'Listado de Reservas:<br>';
echo $listadoUsuarios['nombre'].'<br>';
}