i'm using the following to count the number of rows in my table:
$book_count = query("SELECT status FROM scifi_book WHERE read = $uid");
(count($book_count));
echo $book_count;
and i get the following error:
Notice: Array to string conversion on line 167
(which is the line echo $book_count;
)
FIY, the query
function is defined and works fine. Never had any issues to insert, select, update and delete.
Am I missing something here?
Try this:
$book_count = query("SELECT status FROM scifi_book WHERE read = $uid");
echo count($book_count);
Also, you need to use print_r($book_count)
since your $book_count
is not a string.
your query function seems to return an array, not a string. Instead of echo $follower_count
use print_r($follower_count)
to see what's inside the query response.
Suggestion: if you only use that query for getting the count, this may be a bit better:
$book_count = query("SELECT count(*) FROM scifi_book WHERE read = $uid");
The reason you are seeing that error is because you are echo
ing Array
which is the returned by your query
function. echo
construct only works on strings, please see the documentation here: http://www.php.net/manual/en/function.echo.php.
Had you used print_r
or var_dump
then you wouldn't have seen that error. So as @A.S. Roma and Nathaniel Granor suggest use print_r
$book_count = query("SELECT status FROM scifi_book WHERE read =".$uid);
(count($book_count));
echo $book_count;