打印出 COUNT - SQL / PHP
我有以下代码:
$topics= mysql_query("SELECT COUNT(*) FROM forum_topics WHERE forum_id=".$h['forum_id']."");
print $topics; //This prints out 1, but should be 14?
如您所见,我从表中选择 COUNT。该表包含 14 行。我怎样才能打印出来?现在,当我打印 $topics 时,它只是显示 Resource Id #18。
I have this code:
$topics= mysql_query("SELECT COUNT(*) FROM forum_topics WHERE forum_id=".$h['forum_id']."");
print $topics; //This prints out 1, but should be 14?
As you can see, I select COUNT from my table. That table contains 14 rows. How can I print this out? As now, when I print out $topics, it just says Resource Id #18.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你需要做:
You need to do:
那么你需要类似的东西
Then you need something like
$topics
不会打印14
。该查询在成功
时返回资源ID
,在错误
时返回false
。来源:链接。
如果你想获取计数,你可以这样做,
如果你必须获取多条记录,你可以使用
$topics
will not print14
. The query returnsResource ID
onsuccess
andfalse
onerror
.Source: Link.
If you want to get the Count you can do,
If you have to get multiple records you can use
这是因为 $topics 是一种资源,而不是结果集。您需要使用 mysql_fetch_assoc、mysql_fetch_array 获取结果集(数组),或者在这种情况下可以使用 mysql_fetch_row。
http://us.php.net/manual/en/ref.mysql.php
That is because $topics is a resource, not a result set. You need to get a result set(array) using mysql_fetch_assoc, mysql_fetch_array, or you can use mysql_fetch_row in this case.
http://us.php.net/manual/en/ref.mysql.php