计算视图中的结果数
我需要计算有多少人属于预定义的组(这在 SQL 中使用 SELECT COUNT 语句很容易做到).我的视图查询运行良好并在我的表中显示实际数据,但我只需要知道它找到了多少结果.
I need to count how many people belong in pre-defined groups (this is easy to do in SQL using the SELECT COUNT statement). My Views query runs fine and displays the actual data in my table, but I simply need to know how many results it found.
但是,视图中似乎没有 COUNT 选项.我猜我将不得不使用某种视图挂钩,然后将结果粘贴到表格中.
However there doesn't seem to be a COUNT option in views. I am guessing I am going to have to use some sort of views hook, and then stick the result in the table.
这是我想要实现的目标的一个简单示例:
Here's a quick example of what i'm trying to achieve:
My Table
----------------------
Group A | 20 people
Group B | 63 people
等等.
(我已经尝试使用 Views_Calc 模块,但我收到错误,因为它还不是很稳定.)
(I've tried using the Views_Calc module, but I get errors because it is not quite stable yet.)
有人知道一种简单的方法来计算视图中的结果吗?
Anybody know of an easy way to count results in Views?
推荐答案
这是一个很好的 d.o 主题:http://drupal.org/node/131031
Here's a good d.o thread about it: http://drupal.org/node/131031
尽管如果您只需要计数而不是 Views 提供的其他内容(字段格式和排序等),为什么不编写正确的 SELECT COUNT 语句并收工呢?
Although if you JUST need the count and not the other things Views offers (field formatting & ordering, etc), why not just code up the proper SELECT COUNT statement and call it a day?
(如果您确实需要 Views 提供的那些其他作品,上面有很多关于该线程的示例.)
(If you DO in fact need those other pieces Views offers, there are many examples on that thread above.)
相关文章