0

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?

4

5 回答 5

2

尝试这个:

$book_count = query("SELECT status FROM scifi_book WHERE read = $uid");
echo count($book_count);

此外,您需要使用,print_r($book_count)因为您$book_count的不是字符串。

于 2013-07-05T18:20:25.743 回答
2

建议:如果您只使用该查询来获取计数,这可能会更好一些:

$book_count = query("SELECT count(*) FROM scifi_book WHERE read = $uid");
于 2013-07-05T18:26:50.170 回答
1

您的查询函数似乎返回一个数组,而不是一个字符串。而不是echo $follower_count用来print_r($follower_count)查看查询响应中的内容。

于 2013-07-05T18:21:13.180 回答
1

您看到该错误的原因是因为您正在echoingArray这是您的query函数返回的。 echo构造仅适用于字符串,请参阅此处的文档:http ://www.php.net/manual/en/function.echo.php 。

如果您使用过print_r,否则var_dump您将不会看到该错误。所以@AS Roma 和 Nathaniel Granor 建议使用print_r

于 2013-07-05T18:26:57.200 回答
1
$book_count = query("SELECT status FROM scifi_book WHERE read =".$uid);
(count($book_count));
echo $book_count;
于 2013-07-05T18:28:16.757 回答