I get this error when I try to put the id
on button
Fatal error: Cannot use object of type PDOStatement as array...
The code where is the error is this
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$q = "SELECT * FROM books where user = '".$_SESSION['level']."'";
if($res = $pdo->query($q))
{
if($res->fetchColumn() > 0)
{
foreach($pdo->query($q) as $res)
{
echo '<a href="users/books.php?user_id='. $res['user_id'] .'"> '.$res['name'].' </a>';
}
}
else
{
echo '<a href="users/bookAdd.php?user_id='. $res['user_id'] .'">Create Book</a>';
}
}
Database::disconnect();
What I trying is when user log if there is no books to show him button Create book
. And the error is there in the else block where is users/bookAdd.php?user_id='. $res['user_id'] .'
Any idea how to fix this?