计算视图中的结果数

2023-06-22php开发问题
1

本文介绍了计算视图中的结果数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我需要计算有多少人属于预定义的组(这在 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.)

这篇关于计算视图中的结果数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17