I am using PDO and trying to display how many users are in a table, however I get this error:
Notice: Array to string conversion in C:\Users\admin.phtml on line 10 Array
Then in my Admin class:
public function CountUsers()
{
$query = "SELECT * FROM Users";
$statement = $this->_dbHandle->prepare($query);
// Then execute the query
$statement->execute();
// This will return the row from the database as an array
return $statement->fetchAll(PDO::FETCH_ASSOC);
}
Then in my Admin Controller I have:
$Admin = new Admin();
$CountUsers = $Admin->CountUsers();
To display the results I have this in my phtml:
<var><?php echo $CountUsers; ?></var>
Does anyone understand what I am doing wrong?
echo count($CountUsers);insteadfetchAll()returns an array. You store that array into$CountUsers, so you can'techoit directly. Either access an element likeecho $CountUsers['somekey']orcount($CountUsers)COUNT()