Count number of results in a View(计算视图中的结果数)
问题描述
我需要计算有多少人属于预定义的组(这在 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.)
这篇关于计算视图中的结果数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:计算视图中的结果数


- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01